def getUser(conn, email): email = conn.escape_string(email) user = viddb.load(conn, 'users', viddb.COLS['users'], where= "email = \"%s\"" % email) user = user and user[0] or None return user
def retrieveVideos(conn, youtube_ids): cursor = conn.cursor() if not youtube_ids: return [] where_str = 'youtube_id IN (%s)' % \ ','.join(['"%s"'%y for y in youtube_ids]) c = viddb.COLS['youtube_videos'] resp = viddb.load(conn, 'youtube_videos', viddb.COLS['youtube_videos'], where = where_str) pprint.pprint( resp ) return resp
def listUserTags(conn, userID): tagEntries = viddb.load( conn, 'tags', viddb.COLS['tags'], 'user_id = %s' % userID ) tagMap = {} for e in tagEntries: tagName = e['tag_name'] tagMap[tagName] = tagMap.get(tagName,[]) tagMap[tagName].append( e['youtube_id'] ) tagList = tagMap.items() tagList = sorted( tagList, key = lambda i: len(i[1]), reverse = True ) return tagList
def tset_fbid(conn, fbid, uid=None): cursor = conn.cursor() resp = viddb.load(conn, 'user_foreign_map', ['user_id'], where="network=1 && foreign_id=%s" % fbid) if resp: return resp[0]['user_id'] if not uid: uid = create_user(cursor, subdomain='', origin_network = 1) viddb.insert(cursor, 'user_foreign_map', **{'network':1, 'foreign_id':fbid, 'user_id':uid, '_ignore':True }) return uid
def listSavedVideos(conn, playlist_id): cursor = conn.cursor() keys = ['youtube_id', 'next_id', 'id'] resp = viddb.load(conn, 'playlist_youtube_map', keys, where='playlist_id=%s' % playlist_id) if not resp: return [] tail = filter( lambda n: n['next_id'] is None, resp ) assert tail, "TAIL node not found" tail = tail[0] resp_map = dict([ (n['next_id'], n) for n in resp ] ) ordered_resp = [tail['youtube_id']] current_node = resp_map.get(tail['id'],None) while current_node: ordered_resp.append(current_node['youtube_id']) current_node = resp_map.get(current_node['id']) return ordered_resp
def listPlaylists(conn, user_id): return viddb.load(conn, 'playlists', viddb.COLS['playlists'], where='user_id=%s'%user_id)