コード例 #1
0
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)
コード例 #2
0
ファイル: stats.py プロジェクト: Narii1416/youtify
    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()
コード例 #3
0
ファイル: stats.py プロジェクト: Erkan-Yilmaz/youtify
    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()
コード例 #4
0
ファイル: search.py プロジェクト: Erkan-Yilmaz/youtify
 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))
コード例 #5
0
ファイル: test_playlists.py プロジェクト: jensnockert/youtify
    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')
コード例 #6
0
ファイル: test_playlists.py プロジェクト: jensnockert/youtify
    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()))
コード例 #7
0
ファイル: playlists.py プロジェクト: jensnockert/youtify
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) + ']'
コード例 #8
0
 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))
コード例 #9
0
ファイル: playlists.py プロジェクト: melpomene/youtify
    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)
コード例 #10
0
ファイル: stats.py プロジェクト: glesperance/youtify
    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()
コード例 #11
0
ファイル: test_playlists.py プロジェクト: jensnockert/youtify
    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())
コード例 #12
0
ファイル: stats.py プロジェクト: glesperance/youtify
    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()
コード例 #13
0
    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()
コード例 #14
0
ファイル: playlists_toplist.py プロジェクト: MOZGIII/youtify
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)