Beispiel #1
0
    def get(self): 
        batchid = self.request.get('batchid') 
        batch = db.get(batchid) 

        uobjects = []
        for user in batch.users:
            if User.all().filter("nickname=", user).count() > 0:
                continue
            #TODO query FF for the users prescriptions
            n = random.randint(1,10)
            friends = [ ("user%02d" % (random.randint(0,19))) for i in range(n)]
            u = User( nickname = user, friends = friends)
            uobjects += [ u ] 
        db.put(uobjects)
        batch.done = True 
        key = db.Key( str(batch.parent_key() ))
        batch.delete()
        #nbatches = Batch.all().ancestor( key ).filter("done=", True).count() 
        nbatches = Batch.all(keys_only=True)
        nbatches = nbatches.ancestor( key ) 
        nbatches = nbatches.count() 
        logging.info("nbatches=%d" % nbatches)
        if nbatches == 0: 
            job = db.get( key )
            job.done = True 
            job.put() 
            t = Task(method="GET", url="/tasks/FinishJob?jobid=%s" % job.key())
            t.add()
Beispiel #2
0
    def post(self):
        user_id = self.request.get('user_id')
        password = self.request.get('password')

        # 验证是否重复添加
        users = User.all().filter('owner =', current_user)
        count = users.filter('user_id =', user_id).count()
        if count:
            json.dump({ 'error': True, 'reason': u'用户已存在' },
                    self.response.out)
            return

        # 验证用户名密码是否正确
        headers = {
                'Authorization': 'Basic ' +
                    base64.b64encode('%s:%s' %
                        (user_id.encode('utf8'), password.encode('utf8'))),
                }
        try:
            resp = urlfetch.fetch(
                    'http://api.fanfou.com/account/verify_credentials.json',
                    headers=headers, deadline=10)
        except Exception, e:
            json.dump({ 'error': True, 'reason': u'错误 ' + repr(e) },
                    self.response.out)
Beispiel #3
0
 def get(self): 
     jobid = self.request.get('jobid') 
     job = db.get(jobid) 
     job.ready = True
     users = User.all().filter("nickname IN", job.users)
     job.scores = [ 0. ] * len(job.users)
     for user in users:
         name = user.nickname
         idx = job.users.index(name)
         #TODO: calculate scores another way
         n = len(filter(lambda x: job.users.count(name)>0, user.friends))
         job.scores[idx] = float(n)
         #TODO: don't delete if caching
         user.delete()
     job.put() 
Beispiel #4
0
 def post(self):
     status = self.request.get('status')
     user_id = self.request.get('user_id')
     user = User.all().filter('owner =', current_user)
     user = user.filter('user_id =', user_id).fetch(1)[0]
     if status:
         plan_time = datetime.strptime(self.request.get('plan_time'), 
                                       '%Y-%m-%d %H:%M') - utc_fix
         interval = int(self.request.get('interval'))
         if interval and plan_time <= datetime.now():
             plan_time = next_time(plan_time, interval)
         Plan(user=user,
              status=status,
              plan_time=plan_time,
              interval=interval
              ).put()
     json.dump(get_user_plans(user), self.response.out)
Beispiel #5
0
    def post(self):
        user_id = self.request.get('user_id')
        users = User.all().filter('owner =', current_user)
        the_user = users.filter('user_id =', user_id)
        if not the_user.count():
            return
        the_user = the_user.fetch(1)[0]
        plans = Plan.all().filter('user ='******'users': convert_users_list(users),
                'plans': get_user_plans(users[0]) if users else [],
                }
        json.dump(data, self.response.out)
Beispiel #6
0
def get_users_list():
    return [user for user in User.all().filter('owner =', current_user)]
Beispiel #7
0
 def get(self, user_id):
     user_id = urllib.unquote(user_id).decode('utf8')
     user = User.all().filter('owner =', current_user)
     user = user.filter('user_id =', user_id).fetch(1)[0]
     json.dump(get_user_plans(user), self.response.out)