def fetch_toplist(): """Fetch the most popular playlists""" json = [] for m in Playlist.all().filter('private =', False).order('-nr_of_followers').fetch(100): json.append(get_playlist_struct_from_playlist_model(m)) return simplejson.dumps(json)
def get(self): stats = Stats() stats.nr_of_users = 0 stats.nr_of_active_users = 0 try: stats.nr_of_playlists = Playlist.all(keys_only=True).count(read_policy=EVENTUAL_CONSISTENCY) except: pass stats.nr_of_users_with_flattr_account = 0 stats.nr_of_users_with_dropbox = 0 try: stats.nr_of_flattrs = Activity.all().filter('type =', 'outgoing').filter('verb =', 'flattr').count(read_policy=EVENTUAL_CONSISTENCY) except: pass stats.nr_of_playlist_subscriptions = 0 try: stats.nr_of_follow_relations = FollowRelation.all(keys_only=True).count(read_policy=EVENTUAL_CONSISTENCY) except: pass try: for user in YoutifyUser.all(): stats.nr_of_users += 1 if user.flattr_user_name: stats.nr_of_users_with_flattr_account += 1 if user.dropbox_user_name: stats.nr_of_users_with_dropbox += 1 if user.playlist_subscriptions: stats.nr_of_playlist_subscriptions += len(user.playlist_subscriptions) if user.last_login: delta = datetime.now() - user.last_login if delta.seconds < 3600 * 24 * 7: stats.nr_of_active_users += 1 except: pass pings = [] last_ping = None try: for m in PingStats.all().order('-date').fetch(6*24*7): if last_ping is not None and last_ping.date.hour is not m.date.hour: pings.append({ 'date': str(last_ping.date), 'pings': last_ping.pings }) last_ping = m elif last_ping is None or m.pings > last_ping.pings: last_ping = m except: pass stats.pings = simplejson.dumps(pings) stats.put()
def get(self): stats = Stats() stats.nr_of_users = 0 stats.nr_of_active_users = 0 stats.nr_of_playlists = len([i for i in Playlist.all()]) stats.nr_of_users_with_flattr_account = 0 stats.nr_of_flattrs = 0 stats.nr_of_playlist_subscriptions = 0 stats.nr_of_follow_relations = len([i for i in FollowRelation.all()]) for user in YoutifyUser.all(): stats.nr_of_users += 1 if user.flattr_user_name: stats.nr_of_users_with_flattr_account += 1 if user.playlist_subscriptions: stats.nr_of_playlist_subscriptions += len(user.playlist_subscriptions) if user.last_login: delta = datetime.now() - user.last_login if delta.seconds < 3600 * 24 * 7: stats.nr_of_active_users += 1 stats.nr_of_flattrs += len([i for i in Activity.all().filter('owner =', user).filter('verb =', 'flattr')]) stats.put()
def get(self): q = self.request.get('q') ret = [] for m in Playlist.all().search(q, properties=['title']).filter('private =', False): ret.append(get_playlist_struct_from_playlist_model(m)) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(ret))
def test_update_playlists(self): self._post_playlist() playlists = [m for m in Playlist.all()] playlist_model = playlists[0] json = simplejson.dumps({ 'title': 'britney', 'videos': [ { 'title': 'oh baby baby', 'videoId': 'z2Am3aLwu1E', }, ], }) form = 'json=' + json handler = SpecificPlaylistHandler() handler.request = Request({ 'REQUEST_METHOD': 'POST', 'PATH_INFO': '/api/playlists/' + str(playlist_model.key().id()), 'wsgi.input': StringIO(form), 'CONTENT_LENGTH': len(form), 'SERVER_NAME': 'hi', 'SERVER_PORT': '80', 'wsgi.url_scheme': 'http', }) handler.response = Response() handler.post() playlist_model = Playlist.get_by_id(1) json = simplejson.loads(playlist_model.json) self.failUnless(json['title'] == 'britney')
def test_create_playlist(self): response = self._post_playlist() playlists = [m for m in Playlist.all()] self.failUnless(len(playlists) == 1) self.failUnless(response == str(playlists[0].key().id()))
def get_playlists_json_for_user(youtify_user): playlists = [] for playlist in Playlist.all().filter('owner =', youtify_user): if playlist.json is None: logging.error("Playlist " + str(playlist.key().id()) + " has invalid JSON, skipping...") else: playlists.append(playlist.json) return '[' + ','.join(playlists) + ']'
def get(self): q = self.request.get('q').strip(' \t\n\r') if len(q) < 3: self.response.headers['Content-Type'] = 'application/json' self.response.out.write('[]') return ret = [] for m in Playlist.all().search(q, properties=['title']).filter( 'private =', False).fetch(30): ret.append(get_playlist_struct_from_playlist_model(m)) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(ret))
def get(self): """Get playlists for logged in user""" youtify_user = get_current_youtify_user() playlists = [] for playlist in Playlist.all().filter('owner =', youtify_user): if playlist.json is None: logging.error("Playlist " + str(playlist.key().id()) + " has invalid JSON, skipping...") else: playlists.append(playlist.json) output = '[' + ','.join(playlists) + ']' self.response.headers['Content-Type'] = 'application/json' self.response.out.write(output)
def get(self): stats = Stats() stats.nr_of_users = 0 stats.nr_of_active_users = 0 stats.nr_of_playlists = len([i for i in Playlist.all()]) stats.nr_of_users_with_flattr_account = 0 stats.nr_of_flattrs = len([ i for i in Activity.all().filter('type =', 'outgoing').filter( 'verb =', 'flattr') ]) stats.nr_of_playlist_subscriptions = 0 stats.nr_of_follow_relations = len([i for i in FollowRelation.all()]) for user in YoutifyUser.all(): stats.nr_of_users += 1 if user.flattr_user_name: stats.nr_of_users_with_flattr_account += 1 if user.playlist_subscriptions: stats.nr_of_playlist_subscriptions += len( user.playlist_subscriptions) if user.last_login: delta = datetime.now() - user.last_login if delta.seconds < 3600 * 24 * 7: stats.nr_of_active_users += 1 pings = [] last_ping = None for m in PingStats.all().order('-date').fetch(6 * 24 * 7): if last_ping is not None and last_ping.date.hour is not m.date.hour: pings.append({ 'date': str(last_ping.date), 'pings': last_ping.pings }) last_ping = m elif last_ping is None or m.pings > last_ping.pings: last_ping = m stats.pings = simplejson.dumps(pings) stats.put()
def test_get_playlists(self): self._post_playlist() playlists = [m for m in Playlist.all()] playlist_model = playlists[0] handler = PlaylistsHandler() handler.request = Request({ 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/api/playlists', 'SERVER_NAME': 'hi', 'SERVER_PORT': '80', 'wsgi.url_scheme': 'http', }) handler.response = Response() handler.get() response = handler.response.out.getvalue() response = simplejson.loads(response) self.failUnless(response[0]['title'] == 'lopez') self.failUnless(response[0]['remoteId'] == playlist_model.key().id())
def get(self): stats = Stats() stats.nr_of_users = 0 stats.nr_of_active_users = 0 stats.nr_of_playlists = len([i for i in Playlist.all()]) stats.nr_of_users_with_flattr_account = 0 stats.nr_of_flattrs = len([i for i in Activity.all().filter('type =', 'outgoing').filter('verb =', 'flattr')]) stats.nr_of_playlist_subscriptions = 0 stats.nr_of_follow_relations = len([i for i in FollowRelation.all()]) for user in YoutifyUser.all(): stats.nr_of_users += 1 if user.flattr_user_name: stats.nr_of_users_with_flattr_account += 1 if user.playlist_subscriptions: stats.nr_of_playlist_subscriptions += len(user.playlist_subscriptions) if user.last_login: delta = datetime.now() - user.last_login if delta.seconds < 3600 * 24 * 7: stats.nr_of_active_users += 1 pings = [] last_ping = None for m in PingStats.all().order('-date').fetch(6*24*7): if last_ping is not None and last_ping.date.hour is not m.date.hour: pings.append({ 'date': str(last_ping.date), 'pings': last_ping.pings }) last_ping = m elif last_ping is None or m.pings > last_ping.pings: last_ping = m stats.pings = simplejson.dumps(pings) stats.put()
def get(self): stats = Stats() stats.nr_of_users = 0 stats.nr_of_active_users = 0 try: stats.nr_of_playlists = Playlist.all(keys_only=True).count( read_policy=EVENTUAL_CONSISTENCY) except: pass stats.nr_of_users_with_flattr_account = 0 stats.nr_of_users_with_dropbox = 0 try: stats.nr_of_flattrs = Activity.all().filter( 'type =', 'outgoing').filter( 'verb =', 'flattr').count(read_policy=EVENTUAL_CONSISTENCY) except: pass stats.nr_of_playlist_subscriptions = 0 try: stats.nr_of_follow_relations = FollowRelation.all( keys_only=True).count(read_policy=EVENTUAL_CONSISTENCY) except: pass try: for user in YoutifyUser.all(): stats.nr_of_users += 1 if user.flattr_user_name: stats.nr_of_users_with_flattr_account += 1 if user.dropbox_user_name: stats.nr_of_users_with_dropbox += 1 if user.playlist_subscriptions: stats.nr_of_playlist_subscriptions += len( user.playlist_subscriptions) if user.last_login: delta = datetime.now() - user.last_login if delta.seconds < 3600 * 24 * 7: stats.nr_of_active_users += 1 except: pass pings = [] last_ping = None try: for m in PingStats.all().order('-date').fetch(6 * 24 * 7): if last_ping is not None and last_ping.date.hour is not m.date.hour: pings.append({ 'date': str(last_ping.date), 'pings': last_ping.pings }) last_ping = m elif last_ping is None or m.pings > last_ping.pings: last_ping = m except: pass stats.pings = simplejson.dumps(pings) stats.put()
def fetch_toplist(): """Fetch the most popular playlists""" json = [] for m in Playlist.all().filter('private =', False).order('-nr_of_followers').fetch(100): json.append(get_playlist_struct_from_playlist_model(m)) return simplejson.dumps(json)