コード例 #1
0
ファイル: api.py プロジェクト: mohayonao/YouHaShock
        def write_user_ranking(type, limit):
            key_name = 'ranking_%s' % type
            lst = memcache.get(key_name)
            if not isinstance(lst, list):
                lst = []
                if type == 'call':
                    query = UserStatus.all().order('-call_count')
                else:
                    query = UserStatus.all().order('-callee_count')
                    
                for ent in query:
                    name = ent.key().name()[3:]
                    if name in blocklist: continue

                    profile_image_url = ent.profile_image_url
                    if type == 'call':
                        count = ent.call_count
                    else:
                        count = ent.callee_count
                    lst.append( (name, profile_image_url,count) )
                    limit -= 1
                    if limit < 0: break
                memcache.set(key=key_name, value=lst, time=120)
                
            for l in lst:
                self.response.out.write("['%s','%s',%d]," % (l[0], l[1], l[2]))
コード例 #2
0
ファイル: api.py プロジェクト: mohayonao/YouHaShock
    def get_graph(self):
        """ユーザーグラフを返す"""
        
        name = self.request.get('name')
        if not name: return 'null'
        
        key_name = 'at_%s' % name
        ent = UserStatus.get_by_key_name(key_name)
        if not ent: return 'null'


        self.response.out.write('{')
        self.response.out.write('img:"%s",' % (ent.profile_image_url))
        self.response.out.write('call:%d,callee:%d,' % (ent.call_count, ent.callee_count))
        
        if ent.graph:
            try: graph = eval(ent.graph)
            except TypeError: graph = { }
            self.response.out.write('graph:{')
            
            call = graph.get('call', {})
            self.response.out.write('call:{')
            for k, v in call.iteritems():
                self.response.out.write('"%s":%s,' % (k, v))
            self.response.out.write('},')
            
            callee = graph.get('callee', {})
            self.response.out.write('callee:{')
            for k, v in callee.iteritems():
                self.response.out.write('"%s":%s,' % (k, v))
            self.response.out.write('},')
            
            self.response.out.write('}')
            
        self.response.out.write('}')
コード例 #3
0
ファイル: task.py プロジェクト: mohayonao/YouHaShock
 def get(self, action):
     if action == 'request':
         expired = datetime.datetime.now() - datetime.timedelta(minutes=10)
         expired_tokens = OAuthRequestToken.all().filter('created <', expired).fetch(20)
         for token in expired_tokens:
             token.delete()
             
     elif action == 'access':
         expired = datetime.datetime.now() - datetime.timedelta(hours=6)
         expired_tokens = OAuthAccessToken.all().filter('modified <', expired).fetch(20)
         
         q = taskqueue.Queue('background')
         for i, token in enumerate(expired_tokens):
             key_name = token.key().name()
             t = taskqueue.Task(url='/task/access', params=dict(key_name=key_name), countdown=i*2)
             q.add(t)
     
     elif action == 'graph':
         q = taskqueue.Queue('fastest')
         t = taskqueue.Task(url='/task/graph')
         q.add(t)
         
     elif action == 'image':
         expired = datetime.datetime.now() - datetime.timedelta(days=7)
         expired_tokens = UserStatus.all().filter('profile_image_updated <', expired).fetch(10)
         
         q = taskqueue.Queue('background')
         for i, token in enumerate(expired_tokens):
             key_name = token.key().name()
             t = taskqueue.Task(url='/task/image', params=dict(key_name=key_name), countdown=i*2)
             q.add(t)
コード例 #4
0
ファイル: api.py プロジェクト: mohayonao/YouHaShock
    def get_image_url(self):
        """アイコン画像のURLを返す"""
        
        name = self.request.get('name')
        if not name: return 'null'

        key_name = 'at_%s' % name
        url = memcache.get(key=key_name)
        if not url:
            ent = UserStatus.get_by_key_name(key_name)
            if not ent: return 'null'
            url = ent.profile_image_url
            memcache.set(key=key_name, value=url)
        self.response.out.write(url)
コード例 #5
0
ファイル: task.py プロジェクト: mohayonao/YouHaShock
    def update_status(self, name, type, opposite):
        name     = '%s' % name
        key_name = 'at_%s' % name
        ent = UserStatus.get_by_key_name(key_name)
        if not ent:
            ent = UserStatus(key_name=key_name)
            ent.profile_image_url = self.get_profile_image(name)
            ent.put()
            
        if type == 'call':
            ent.call_count += 1
        elif type == 'callee':
            ent.callee_count += 1

        graph = ent.graph or '{ "call":{},"callee":{} }'
        try:
            graph = eval(graph)
        except TypeError:
            graph = { "call":{}, "callee":{} }
            
        graph_item = graph[type]
        graph_item[opposite] = graph_item.get(opposite, 0) + 1
        ent.graph = str(graph)
        ent.put()
コード例 #6
0
ファイル: task.py プロジェクト: mohayonao/YouHaShock
 def update_image(self, key_name):
     ent = UserStatus.get_by_key_name(key_name)
     if not ent: return
     
     name = ent.key().name()[3:]
     logging.debug('profile_image: %s' % name)
     if not ent.profile_image_url:
         try:
             profile_image_url = self.get_profile_image(name)
         except urlfetch.InvalidURLError:
             logging.warning('deleted user?: %s' % name)
             ent.profile_image_updated = datetime.datetime.max
             ent.put()
         else:
             ent.profile_image_url = profile_image_url
             logging.debug('profile_image_url: %s' % ent.profile_image_url)
             if profile_image_url:
                 ent.profile_image_url = profile_image_url
                 ent.profile_image_updated = datetime.datetime.now()
                 ent.put()
             else:
                 logging.warning('profile_image: %s = NONE' % name)
                 
     return