def _event_start(self, event): dt = self._fix_dt(event.get('dtstart').dt) recur = utils.rget(event, 'RRULE.FREQ.0') if recur in TDELTAS: today = datetime.datetime.combine(datetime.date.today(), datetime.time.min) until = utils.rget(event, 'RRULE.UNTIL') if until: until = self._fix_dt(min(until)) while dt < today and (not until or dt < until): dt += TDELTAS[recur] return dt
def get(self, namespace, path, default=None, from_keyring=False): path = '%s.%s' % (namespace, path) if from_keyring: value = keyring.get_password(APPNAME, path) else: value = utils.rget(self.values, path) return value if value is not None else default
def validate_host(self, field, value): if not value: return value url = UPDATE_URL % {'host':value, 'apikey':1234, 'end':'2000-01-01'} response = utils.http_request(url, timeout=2) if utils.rget(response, 'error.code') != 401: raise ValidationError('Host not reachable.') return value
def update(self): endstr = (datetime.now() + timedelta(days=14)).strftime(DATE_FORMAT) update_url = UPDATE_URL % {'host':self.host, 'apikey':self.apikey, 'end':endstr} response = utils.http_request(update_url).get('response') if response: content = json.loads(response.read().decode('utf-8')) self.data['shows'] = [e for e in content if not self._is_ignored(utils.rget(e, 'series.title'))] super(Plugin, self).update()
def validate_host(self, field, value): if not value: return value url = UPDATE_URL % {'host': value, 'apikey': 1234, 'end': '2000-01-01'} response = utils.http_request(url, timeout=2) if utils.rget(response, 'error.code') != 401: raise ValidationError('Host not reachable.') return value
def update_albums(self): albums = [] response = utils.http_request(self.albums_url).get('response') if response: content = json.loads(response.read().decode('utf-8')) self.data['user'] = {} self.data['user']['id'] = utils.rget(content, 'feed.gphoto$user.$t') self.data['user']['name'] = utils.rget(content, 'feed.gphoto$nickname.$t') for entry in utils.rget(content, 'feed.entry', []): title = utils.rget(entry, 'title.$t') numphotos = utils.rget(entry, 'gphoto$numphotos.$t') if title and numphotos and not self._is_ignored(title): album = {} album['id'] = entry['gphoto$id']['$t'] album['title'] = title.split(' - ')[-1] album['date'] = title.split(' - ')[0] album['photos'] = numphotos albums.append(album) self.last_albums_update = int(time.time()) self.data['albums'] = albums
def update(self): response = utils.http_request(self.update_url).get('response') shows = [] if response: content = json.loads(response.read().decode('utf-8')) for stype in ('missed','today','soon','later'): for show in utils.rget(content, 'data.%s' % stype, []): show['datestr'] = self._datestr(stype, show) show['episode'] = "s%se%s" % (show.get('season',''), show.get('episode','')) if not self._is_ignored(show): shows.append(show) self.data['shows'] = shows super(Plugin, self).update()
def validate_apikey(self, field, value): if not value: return value host = self.fields.host.value if host is None: host = self.pkconfig.get(self.namespace, 'host') url = UPDATE_URL % {'host': host, 'apikey': value, 'end': '2000-01-01'} response = utils.http_request(url, timeout=2).get('response') if utils.rget(response, 'error.code') == 401: raise ValidationError('Invalid API key specified.') content = json.loads(response.read().decode('utf-8')) if not isinstance(content, list): raise ValidationError('Invalid response from server.') return value
def validate_apikey(self, field, value): if not value: return value host = self.fields.host.value if host is None: host = self.pkconfig.get(self.namespace, 'host') url = UPDATE_URL % {'host':host, 'apikey':value, 'end':'2000-01-01'} response = utils.http_request(url, timeout=2).get('response') if utils.rget(response, 'error.code') == 401: raise ValidationError('Invalid API key specified.') content = json.loads(response.read().decode('utf-8')) if not isinstance(content, list): raise ValidationError('Invalid response from server.') return value
def update(self): endstr = (datetime.now() + timedelta(days=14)).strftime(DATE_FORMAT) update_url = UPDATE_URL % { 'host': self.host, 'apikey': self.apikey, 'end': endstr } response = utils.http_request(update_url).get('response') if response: content = json.loads(response.read().decode('utf-8')) self.data['shows'] = [ e for e in content if not self._is_ignored(utils.rget(e, 'series.title')) ] super(Plugin, self).update()
def attribute_dblclick(self, value): callback = utils.rget(self.control, value) if not callback: raise Exception('Invalid dblclick callback: %s' % value) self.dblclick_enabled = True self._dblclick.connect(callback)
def update(self): response = utils.http_request(self.update_url).get('response') if response: contents = utils.xml_to_dict(response.read().decode('utf-8')) self.data = utils.rget(contents, 'rss.channel', {}) super(Plugin, self).update()
def get_value(self, data): value = utils.rget(data, self.varpath) for tfilter in self.filters: value = tfilter.apply(value) return value
def open_wunderground(self, widget): url = utils.rget(self.data, 'current_observation.ob_url', 'http://www.wunderground.com') #url = WEBSITE_URL % {'location':self.location} log.info('Opening WUnderground page: %s', url) webbrowser.open(url)
def choose_random_photo(self, album): photo = {} photos_url = PHOTOS_URL % {'username':self.username, 'albumid':album['id']} response = utils.http_request(photos_url).get('response') if response: content = json.loads(response.read().decode('utf-8')) numphotos = utils.rget(content, 'feed.gphoto$numphotos.$t') if numphotos: diceroll = random.randrange(numphotos) entry = utils.rget(content, 'feed.entry')[diceroll] photo['id'] = entry['gphoto$id']['$t'] photo['url'] = entry['content']['src'] photo['title'] = utils.rget(entry, 'title.$t') photo['summary'] = utils.rget(entry, 'summary.$t') photo['timestamp'] = utils.rget(entry, 'gphoto$timestamp.$t') photo['published'] = utils.rget(entry, 'published.$t') photo['width'] = utils.rget(entry, 'gphoto$width.$t') photo['height'] = utils.rget(entry, 'gphoto$height.$t') photo['size'] = int(utils.rget(entry, 'gphoto$size.$t', 0)) photo['credit'] = ', '.join([item['$t'] for item in utils.rget(entry, 'media$group.media$credit')]) for tag, value in utils.rget(entry, 'exif$tags').items(): tagstr = tag.replace('exif$', '') photo[tagstr] = value['$t'] return photo