# Path: braubuddy/output/base.py
# class IOutput(object):
#     """
#     Interface for creating an output for use with :mod:`braubuddy`.
# 
#     :param units: Temperature units to output.
#     :type units: :class:`str`
#     """
# 
#     __metaclass__ = abc.ABCMeta
# 
#     def __init__(self, units='celsius'):
# 
#         self.set_units(units)
# 
#     def set_units(self, new_units):
#         """
#         Set units to output.
# 
#         :param units: Temperature units to output.
#         :type units: :class:`str`
#         """
# 
#         try:
#             self.units = utils.map_temp_units_to_symbol(new_units)
#         except:
#             raise OutputError('Unrecognised units: {0}'.format(new_units))
# 
#     @abc.abstractmethod
#     def publish_status(self, target, temp, heater_percent, cooler_percent):
#         """
#         Publish braubuddy status
# 
#         :param target: Target temperature.
#         :type target: :class:`float`
#         :param temp: Current temperature.
#         :type temp: :class:`float`
#         :param heater_percent: Current heater power level as percentage.
#         :type heater_percent: :class:`float`
#         :param cooler_percent: Current cooler power level as percentage.
#         :type coolerer_percent: :class:`float`
#         """
# 
# Path: braubuddy/output/base.py
# class OutputError(Exception):
#     """
#     Raised whenever an output fails
#     """


import os
import twitter
from datetime import datetime
from xdg import BaseDirectory
from cherrypy import log
from braubuddy.output import IOutput
from braubuddy.output import OutputError
            * temp (actual temperature)
            * target (target temperature)
            * units (temperature units)
            * heat (heater level)
            * cool (cooler level)
    :type message: :class:`str`
    """

    def __init__(self, units='celsius', frequency=1440,
                 message='Environment Status: Temp {temp}{units} | Target '
                         '{target}{units} | Heat {heat}% | Cool {cool}% '
                         '#braubuddy http://braubuddy.org'):

        self._frequency = frequency
        self._message = message
        self._api = self._get_credentials(CREDS_FILE)
        self._last_published = datetime.now()
        super(TwitterAPIOutput, self).__init__(units)

    def _get_credentials(self, creds_file):
        """
        Get Twitter credentials from file if one exists. Otherwise request
        credentials via oauth.
        """

        if not os.path.exists(creds_file):
            print 'Authorising with Twitter...'
            try:
                twitter.oauth_dance(APP, TCK, TCS, creds_file)
            except twitter.TwitterHTTPError as err:

# Path: braubuddy/output/base.py
# class IOutput(object):
#     """
#     Interface for creating an output for use with :mod:`braubuddy`.
# 
#     :param units: Temperature units to output.
#     :type units: :class:`str`
#     """
# 
#     __metaclass__ = abc.ABCMeta
# 
#     def __init__(self, units='celsius'):
# 
#         self.set_units(units)
# 
#     def set_units(self, new_units):
#         """
#         Set units to output.
# 
#         :param units: Temperature units to output.
#         :type units: :class:`str`
#         """
# 
#         try:
#             self.units = utils.map_temp_units_to_symbol(new_units)
#         except:
#             raise OutputError('Unrecognised units: {0}'.format(new_units))
# 
#     @abc.abstractmethod
#     def publish_status(self, target, temp, heater_percent, cooler_percent):
#         """
#         Publish braubuddy status
# 
#         :param target: Target temperature.
#         :type target: :class:`float`
#         :param temp: Current temperature.
#         :type temp: :class:`float`
#         :param heater_percent: Current heater power level as percentage.
#         :type heater_percent: :class:`float`
#         :param cooler_percent: Current cooler power level as percentage.
#         :type coolerer_percent: :class:`float`
#         """
# 
# Path: braubuddy/output/base.py
# class OutputError(Exception):
#     """
#     Raised whenever an output fails
#     """


# Path: braubuddy/output/twitterapi.py
import os
import twitter
from datetime import datetime
from xdg import BaseDirectory
from cherrypy import log
from braubuddy.output import IOutput
from braubuddy.output import OutputError

            * temp (actual temperature)
            * target (target temperature)
            * units (temperature units)
            * heat (heater level)
            * cool (cooler level)
    :type message: :class:`str`
    """

    def __init__(self, units='celsius', frequency=1440,
                 message='Environment Status: Temp {temp}{units} | Target '
                         '{target}{units} | Heat {heat}% | Cool {cool}% '
                         '#braubuddy http://braubuddy.org'):

        self._frequency = frequency
        self._message = message
        self._api = self._get_credentials(CREDS_FILE)
        self._last_published = datetime.now()
        super(TwitterAPIOutput, self).__init__(units)

    def _get_credentials(self, creds_file):
        """
        Get Twitter credentials from file if one exists. Otherwise request
        credentials via oauth.
        """

        if not os.path.exists(creds_file):
            print 'Authorising with Twitter...'
            try:
                twitter.oauth_dance(APP, TCK, TCS, creds_file)
            except twitter.TwitterHTTPError as err:

                raise OutputError(err)