コード例 #1
0
ファイル: lcd_daemon.py プロジェクト: safarmer/kegbot
 def ThreadMain(self):
   self._logger.info('Starting main loop.')
   while not self._quit:
     self._logger.info('Fetching krest status')
     try:
       tap_status = self._client.TapStatus()
       self._lcdui.UpdateFromTapStatus(tap_status)
       last_drink = None
       last_drinks = self._client.LastDrinks().drinks
       if last_drinks:
         last_drink = last_drinks[0]
       username = '******'
       if last_drink.user_id:
         username = str(last_drink.user_id)
       date = util.iso8601str_to_datetime(last_drink.pour_time, TIME_ZONE)
       self._lcdui.UpdateLastDrink(username, last_drink.volume_ml, date)
     except IOError, e:
       self._logger.warning('Could not connect to kegweb: %s' % e)
     time.sleep(FLAGS.krest_update_interval)
コード例 #2
0
 def ThreadMain(self):
     self._logger.info('Starting main loop.')
     while not self._quit:
         self._logger.info('Fetching krest status')
         try:
             tap_status = self._client.TapStatus()
             self._lcdui.UpdateFromTapStatus(tap_status)
             last_drink = None
             last_drinks = self._client.LastDrinks().drinks
             if last_drinks:
                 last_drink = last_drinks[0]
             username = '******'
             if last_drink.user_id:
                 username = str(last_drink.user_id)
             date = util.iso8601str_to_datetime(last_drink.pour_time,
                                                TIME_ZONE)
             self._lcdui.UpdateLastDrink(username, last_drink.volume_ml,
                                         date)
         except IOError, e:
             self._logger.warning('Could not connect to kegweb: %s' % e)
         time.sleep(FLAGS.krest_update_interval)
コード例 #3
0
ファイル: kbjson.py プロジェクト: Alwnikrotikz/kegbot
def _ToAttrDict(obj):
  """JSONDecoder object_hook that translates dicts and ISO times.

  Dictionaries are converted to AttrDicts, which allow element access by
  attribute (getattr).

  Also, an attempt will be made to convert any field ending in 'date' or 'time'
  to a datetime.datetime object.  The format is expected to match the ISO8601
  format used in JSONEncoder.  If it does not parse, the value will be left as a
  string.
  """
  if type(obj) == types.DictType:
    # Try to convert any "time" or "date" fields into datetime objects.  If the
    # format doesn't match, just leave it alone.
    for k, v in obj.iteritems():
      if k.endswith('date') or k.endswith('time') or k.startswith('date') or k.startswith('last_login'):
        try:
          obj[k] = util.iso8601str_to_datetime(v, TIME_ZONE)
        except ValueError:
          pass
    return util.AttrDict(obj)
  return obj
コード例 #4
0
def _ToAttrDict(obj):
    """JSONDecoder object_hook that translates dicts and ISO times.

  Dictionaries are converted to AttrDicts, which allow element access by
  attribute (getattr).

  Also, an attempt will be made to convert any field ending in 'date' or 'time'
  to a datetime.datetime object.  The format is expected to match the ISO8601
  format used in JSONEncoder.  If it does not parse, the value will be left as a
  string.
  """
    if type(obj) == types.DictType:
        # Try to convert any "time" or "date" fields into datetime objects.  If the
        # format doesn't match, just leave it alone.
        for k, v in obj.iteritems():
            if k.endswith('date') or k.endswith('time') or k.startswith(
                    'date') or k.startswith('last_login'):
                try:
                    obj[k] = util.iso8601str_to_datetime(v, TIME_ZONE)
                except ValueError:
                    pass
        return util.AttrDict(obj)
    return obj