def GET(self): rdio, current_user, user_id = get_rdio_and_current_user() if rdio and current_user: if user_id in config.ADMIN_USERS: form_input = get_input() if 'button' in form_input.keys(): action = form_input['button'] db = get_db() if action == 'doitnow_go_on_killme': if user_id in config.ADMIN_USERS: db.delete(USER_TABLE, where="rdio_user_id=%i" % user_id) raise web.seeother('/') elif action == 'clear_preferences': if user_id in config.ADMIN_USERS: db.update(USER_TABLE, where="rdio_user_id=%i" % user_id, prefs=BSONPostgresSerializer.from_dict({})) raise web.seeother('/admin') else: content=get_admin_content() db = get_db() users = db.select(USER_TABLE, what='rdio_user_id, last_use') users = dict([('s%s' % u['rdio_user_id'], u['last_use']) for u in users]) rdio_users = rdio.call('get', {'keys': ','.join(users.keys()), 'extras': '-*,username,url'})['result'] user_list = [(u['username'], u['url'], users[uid]) for uid, u in rdio_users.items()] user_list.sort(key=lambda x: x[2], reverse=True) return render.admin(env_message=get_environment_message(), admin=content, users=user_list) raise web.seeother('/')
def GET(self): rdio, currentUser, user_id = get_rdio_and_current_user() if rdio and currentUser: if user_id in config.ADMIN_USERS: input = get_input() if 'button' in input.keys(): action = input['button'] db = get_db() if action == 'doitnow_go_on_killme': if user_id in config.ADMIN_USERS: db.delete(USER_TABLE, where="rdio_user_id=%i" % user_id) raise web.seeother('/') elif action == 'clear_preferences': if user_id in config.ADMIN_USERS: db.update(USER_TABLE, where="rdio_user_id=%i" % user_id, prefs=BSONPostgresSerializer.from_dict({})) raise web.seeother('/admin') else: admin=get_admin_content() return render.admin(env_message=get_environment_message(), admin=admin) raise web.seeother('/')
def GET(self): rdio, currentUser, user_id = get_rdio_and_current_user() if rdio and currentUser: if not_allowed(user_id): raise web.seeother('/logout') disco_user, message = get_discoversong_user(user_id) stats.visited(user_id) # circular import from discoversong.sources import SourceAppsManager return render.loggedin(name=currentUser['firstName'], message=message, sourceapps=SourceAppsManager.ALL, env_message=get_environment_message()) else: return render.loggedout(env_message=get_environment_message())
def GET(self): svc, current_user, user_id = get_rdio_and_current_user() if svc and current_user: if not_allowed(user_id): raise web.seeother('/logout') disco_user, prefs = get_discoversong_user(user_id) stats.visited(user_id) # circular import from discoversong.sources import SourceAppsManager return render.loggedin(params=Params(user=disco_user, preferences=prefs, message="", environment_message=get_environment_message()), name=current_user['firstName'], sourceapps=SourceAppsManager.ALL) else: return render.loggedout(env_message=get_environment_message())
def GET(self): svc, current_user, user_id = get_rdio_and_current_user() if svc and current_user: if user_id in config.ADMIN_USERS: db = get_db() db_users = db.select(USER_TABLE, what='*') return render.admin_users(env_message=get_environment_message(), users=db_users) raise web.seeother('/')
def GET(self): rdio, currentUser, user_id = get_rdio_and_current_user() disco_user, message = get_discoversong_user(user_id) prefs = BSONPostgresSerializer.to_dict(disco_user['prefs']) # circular import from discoversong.sources import SourceAppsManager return render.config(user=disco_user, prefs=prefs, capabilities=SourceAppsManager.all_capabilities(), editform=editform(playlists=rdio.call('getPlaylists')['result']['owned'], prefs=get_db_prefs(user_id)), env_message=get_environment_message(), message=message)
def POST(self, show_number, episode_number): inputs = web.input() rdio, current_user, user_id = get_rdio_and_current_user() disco_user, prefs = get_discoversong_user(user_id) songs = EpisodeImporter().scrape_songs(episode_number) importing = [] for song in songs: new_query = inputs.get('query_%s' % song.hash()) if new_query != song.query: song.query = new_query for r in search(song): new_import = inputs.get('import_keys_%i_%s' % (song.hash(), r.key)) if new_import: if r.key not in importing: importing.append(r.key) action = inputs.get('submit') if action.startswith('Retry'): return render.import_episode(params=Params(user=disco_user, preferences=prefs, message="", environment_message=get_environment_message()), search=search, importing=importing, show_title=inputs['show_title'], show_number=show_number, episode_title=inputs['episode_title'], episode_number=episode_number, show_url="/import/" + show_number, songs=songs) else: p = rdio.call('createPlaylist', {'name': inputs['pname'], 'description': 'Imported by discoversong on %s' % datetime.datetime.now().strftime('%x'), 'tracks': ','.join(importing), 'isPublished': False})['result'] return web.seeother("/import/%s?p=%s" % (show_number, p['shortUrl']))
def GET(self, show_number, episode_number): episode_url = "http://www.kpfa.org/playlist/id/%i" % int(episode_number) playlist_page = etree.parse(episode_url, etree.HTMLParser()) show_title = try_get(playlist_page, '//div[@class="field-item"]/a/text()') episode_title = try_get(playlist_page, '//div[@class="orangeheader"]/text()', xform=get_episode_title) songs = EpisodeImporter().scrape_songs(episode_number) rdio, current_user, user_id = get_rdio_and_current_user() disco_user, prefs = get_discoversong_user(user_id) return render.import_episode(params=Params(user=disco_user, preferences=prefs, message="", environment_message=get_environment_message()), search=search, importing=[], show_title=show_title, show_number=show_number, episode_title=episode_title, episode_number=episode_number, show_url="/import/" + show_number, songs=songs)
def GET(self, show_number): inputs = web.input() p_url = inputs.get('p') rdio, current_user, user_id = get_rdio_and_current_user() disco_user, prefs = get_discoversong_user(user_id) show_url = "http://www.kpfa.org/playlists/show/" + show_number episodes_page = etree.parse(show_url, etree.HTMLParser()) show_title = try_get(episodes_page, '//div[@class="orangeheader"]/text()') show_title = show_title[:show_title.index(": Playlists")] episode_links = try_get(episodes_page, '//a[starts-with(@href, "/playlist/id/")]') episodes = [] for episode_link in episode_links: title = try_get(episode_link, 'text()', xform=get_episode_title) url = try_get(episode_link, '@href') number = int(url[len("/playlist/id/"):]) episodes.append(episode(title=title, number=number)) return render.list_episodes(params=Params(user=disco_user, preferences=prefs, message="", playlist_url=p_url, environment_message=get_environment_message()), show=show(title=show_title, number=show_number), episodes=episodes)
def GET(self): rdio, current_user, user_id = get_rdio_and_current_user() disco_user, prefs = get_discoversong_user(user_id) programs_page = etree.parse("http://www.kpfa.org/programs/music", etree.HTMLParser()) divs = try_get(programs_page, '//div[@class="node"][.//a[starts-with(@href, "/playlists/show/")]]') shows = [] for div in divs: title = try_get(div, './/h2/a[@title]/@title') playlists_link = try_get(div, './/a[starts-with(@href, "/playlists/show/")]/@href') show_num = int(playlists_link[len("/playlists/show/"):]) shows.append(show(title=title, number=show_num)) return render.list_shows(params=Params(user=disco_user, preferences=prefs, message="", environment_message=get_environment_message()), shows=shows)
def GET(self): rdio, current_user, user_id = get_rdio_and_current_user() disco_user, prefs = get_discoversong_user(user_id) # circular import from discoversong.sources import SourceAppsManager return render.config(params=Params(user=disco_user, preferences=prefs, message="", environment_message=get_environment_message()), capabilities=SourceAppsManager.all_capabilities(), editform=editform(playlists=rdio.call('getPlaylists')['result']['owned'], prefs=get_db_prefs(user_id)))