def check_lastfm(self): s = requests.session() r = s.get(LastFmPlugin.urls['recent_tracks']) resp = json.loads(r.text) try: tracks = resp['recenttracks']['track'] except KeyError: return ev_src = self.event_source('lastfm', 'Last.fm') ev_type = self.event_type(ev_src, 'TrackPlayed') for track in tracks: try: slug = track['date']['uts'] + track['mbid'] except KeyError: continue ev = models.Event(datetime.datetime.utcfromtimestamp( int(track['date']['uts'])), slug, ev_type.id, json.dumps(track)) try: db_session.add(ev) db_session.commit() except IntegrityError: db_session.rollback() dispatcher.add_timer(10, self.check_lastfm)
def check_gh(self): logging.debug('Checking github') s = requests.session() r = s.get('https://api.github.com/users/greghaynes/events') logging.debug('Got status code %d from github' % r.status_code) if r.status_code == 200: self.process_response(r.text) dispatcher.add_timer(1, self.check_gh)
def activate(self): dispatcher.add_timer(0, self.check_lastfm)
def activate(self): self.init_source() dispatcher.add_timer(10, self.check_gh)