def __init__(self, fbid=None, name=None): if fbid is None: try: me = facebook.get('me') if me.status != 200: raise APIError() except OAuthException: raise UnauthorizedError() fbid = me.data['id'] name = me.data['name'] self._fbid = fbid cur = g.db.execute('select loaded from user where fbid = ?', (self._fbid, )) row = cur.fetchone() if row is None: g.db.execute('insert into user values (?, ?, 0);', (self._fbid, name)) g.db.commit() loaded = False else: loaded = row[0] if not loaded: self.load_artists()
def load_artists(self, artist_fbids=None): g.db.execute('delete from likes_artist where user_fbid = ?;', (self._fbid,)) if artist_fbids is None: try: resp = facebook.get('me/music') if resp.status != 200: raise APIError() except OAuthException: raise UnauthorizedError() music = resp.data['data'] artists = filter(lambda item: item['category'] == 'Musician/band', music) values = map(lambda item: (self._fbid, item['id']), artists) else: values = map(lambda artist_fbid: (self._fbid, artist_fbid), artist_fbids) g.db.executemany('insert or ignore into likes_artist values (?, ?);', values) g.db.execute('update user set loaded = 1 where fbid = ?;', (self._fbid,)) g.db.commit()
def load_artists(self, artist_fbids=None): g.db.execute('delete from likes_artist where user_fbid = ?;', (self._fbid, )) if artist_fbids is None: try: resp = facebook.get('me/music') if resp.status != 200: raise APIError() except OAuthException: raise UnauthorizedError() music = resp.data['data'] artists = filter(lambda item: item['category'] == 'Musician/band', music) values = map(lambda item: (self._fbid, item['id']), artists) else: values = map(lambda artist_fbid: (self._fbid, artist_fbid), artist_fbids) g.db.executemany('insert or ignore into likes_artist values (?, ?);', values) g.db.execute('update user set loaded = 1 where fbid = ?;', (self._fbid, )) g.db.commit()
def __init__(self, fbid=None, name=None): if fbid is None: try: me = facebook.get('me') if me.status != 200: raise APIError() except OAuthException: raise UnauthorizedError() fbid = me.data['id'] name = me.data['name'] self._fbid = fbid cur = g.db.execute('select loaded from user where fbid = ?', (self._fbid,)) row = cur.fetchone() if row is None: g.db.execute('insert into user values (?, ?, 0);', (self._fbid, name)) g.db.commit() loaded = False else: loaded = row[0] if not loaded: self.load_artists()