Ejemplo n.º 1
0
 def update(self):
     response = utils.http_request(self.update_url).get('response')
     if response:
         content = response.read().decode('utf-8')
         matches = re.findall(REGEX_IP, content)
         self.data['ip'] = matches[0] if matches else ''
     super(Plugin, self).update()
Ejemplo n.º 2
0
 def update(self):
     response = utils.http_request(self.update_url).get('response')
     if response:
         content = response.read().decode('utf-8')
         matches = re.findall(REGEX_IP, content)
         self.data['ip'] = matches[0] if matches else ''
     super(Plugin, self).update()
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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()
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 def validate_host(self, field, value):
     if not value:
         return value
     url = PING_URL % {'host':value, 'apikey':1234}
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('Host not reachable.')
     if response.status != 200:
         raise ValidationError('Invalid response from server: %s' % response.status)
     return value
Ejemplo n.º 7
0
 def validate_host(self, field, value):
     if not value:
         return value
     url = PING_URL % {'host': value, 'apikey': 1234}
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('Host not reachable.')
     content = json.loads(response.read().decode('utf-8'))
     if 'result' not in content:
         raise ValidationError('Invalid response from server.')
     return value
Ejemplo n.º 8
0
 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()
Ejemplo n.º 9
0
 def validate_apikey(self, field, value):
     if not value:
         return value
     url = UPDATE_URL % {'apikey':value, 'location':'autoip'}
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('No response from Weather Underground.')
     content = json.loads(response.read().decode('utf-8'))
     if 'response' not in content:
         raise ValidationError('Invalid response from Weather Underground.')
     if 'current_observation' not in content:
         raise ValidationError('Invalid API key specified.')
     return value
Ejemplo n.º 10
0
 def validate_apikey(self, field, value):
     if not value:
         return value
     url = UPDATE_URL % {'apikey': value, 'location': 'autoip'}
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('No response from Weather Underground.')
     content = json.loads(response.read().decode('utf-8'))
     if 'response' not in content:
         raise ValidationError('Invalid response from Weather Underground.')
     if 'current_observation' not in content:
         raise ValidationError('Invalid API key specified.')
     return value
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 def _validate_cal(self, field, value):
     if not value:
         field.help.setText(field.help_default)
         return value
     url = Plugin.build_url(value)
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('No response from Google.')
     ical = Calendar.from_ical(response.read().decode('utf-8'))
     title = ical.get('x-wr-calname', ical.get('version', ''))
     if not title:
         raise ValidationError('Invalid response from Google.')
     field.help.setText(title)
     return value
Ejemplo n.º 13
0
 def _validate_cal(self, field, value):
     if not value:
         field.help.setText(field.help_default)
         return value
     url = Plugin.build_url(value)
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('No response from Google.')
     ical = Calendar.from_ical(response.read().decode('utf-8'))
     title = ical.get('x-wr-calname', ical.get('version', ''))
     if not title:
         raise ValidationError('Invalid response from Google.')
     field.help.setText(title)
     return value
Ejemplo n.º 14
0
 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
Ejemplo n.º 15
0
 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()
Ejemplo n.º 16
0
 def validate_query(self, field, value):
     if not value or value == 'autoip':
         self.fields.location.value = 'autoip'
         field.help.setText(field.help_default)
         return value
     url = QUERY_URL % {'query':value}
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('No response from Weather Underground.')
     content = json.loads(response.read().decode('utf-8'))
     if not content.get('RESULTS'):
         raise ValidationError('Unable to determine specified location.')
     result = content['RESULTS'][0]
     self.fields.location.value = result['ll'].replace(' ',',')
     field.help.setText(result['name'])
     return value
Ejemplo n.º 17
0
 def validate_query(self, field, value):
     if not value or value == 'autoip':
         self.fields.location.value = 'autoip'
         field.help.setText(field.help_default)
         return value
     url = QUERY_URL % {'query': value}
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('No response from Weather Underground.')
     content = json.loads(response.read().decode('utf-8'))
     if not content.get('RESULTS'):
         raise ValidationError('Unable to determine specified location.')
     result = content['RESULTS'][0]
     self.fields.location.value = result['ll'].replace(' ', ',')
     field.help.setText(result['name'])
     return value
Ejemplo n.º 18
0
 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 = PING_URL % {'host':host, 'apikey':value}
     response = utils.http_request(url, timeout=2).get('response')
     if not response:
         raise ValidationError('Host not reachable.')
     if response.status != 200:
         raise ValidationError('Invalid response from server: %s' % response.status)
     content = json.loads(response.read().decode('utf-8'))
     if content.get('result') != 'success':
         raise ValidationError('Invalid API key specified.')
     return value
Ejemplo n.º 19
0
 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
Ejemplo n.º 20
0
 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
Ejemplo n.º 21
0
 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()
Ejemplo n.º 22
0
 def update(self):
     response = utils.http_request(self.update_url).get('response')
     if response:
         self.data = json.loads(response.read().decode('utf-8'))
     super(Plugin, self).update()
Ejemplo n.º 23
0
 def update(self):
     response = utils.http_request(self.update_url).get('response')
     if response:
         self.data = json.loads(response.read().decode('utf-8'))
     super(Plugin, self).update()