Esempio n. 1
0
 def getCurrentScore(cls, user):
         if user is None:
                 return None
         userDetails = UserDetails.gql('WHERE  instaright_account = :1', user).get()
         if userDetails is None:
                 logging.info('no user with instaright account %s' % user)
                 userDetails = UserDetails.gql('WHERE  instapaper_account = :1', user).get()
                 if userDetails is None:
                         userDetails=UserDetails()
                         userDetails.instapaper_account=user
                 userDetails.instaright_account=user
                 userDetails.put()
         now =datetime.datetime.now().date()
         currentScore=ScoreUsersDaily.gql('WHERE user = :1 and date = :2', userDetails.key(), now).get()
         if currentScore is None:
                 currentScore = ScoreUsersDaily()
                 currentScore.user=userDetails.key()
                 currentScore.date = now
         return currentScore
Esempio n. 2
0
        def get(self):
                #redirect from appengine domain
                self.redirect_perm()
                self.get_user()

                if self.user_uuid is None or len(str(self.user_uuid)) == 0 or self.screen_name is None or self.user_detail_key is None:
                        logging.info('No cookies, redirecting to home page')
                        self.redirect('/?redirect=/user/dashboard&show_login=1')
                        return
                logging.info('user: %s' %self.instaright_account)
                sessions = SessionModel.gql('WHERE instaright_account = :1 ORDER by date desc ' , self.instaright_account).fetch(self.link_batch)

                score = 0
                links = None
                if sessions is not None:
                        links = [ s for s in sessions if s is not None ]
                ud_key=db.Key(self.user_detail_key)
                logging.info('user detail key %s' % self.user_detail_key)
                template_variables=[]
                now=datetime.datetime.now().date()
                #start_of_week= time.asctime(time.strptime('%s %s 1' %(now.year, now.isocalendar()[1]), '%Y %W %w'))
                start_of_week= datetime.datetime.strptime('%s %s 1' %(now.year, now.isocalendar()[1]), '%Y %W %w')
                memcache_key='user_'+self.user_detail_key+'_score'
                cached_score=memcache.get(memcache_key)
                if cached_score is not None:
                        logging.info('got score from cache( %s ): %s' %( memcache_key, cached_score ))
                        score=cached_score
                else:
                        logging.info('parameters: start of week %s now %s for user_key %s ' % ( start_of_week,now, ud_key))
                        score_entities = ScoreUsersDaily.gql('WHERE user = :1 and date >= :2', ud_key, start_of_week).fetch(100)
                        #score_entities = ScoreUsersDaily.gql('WHERE user = :1 and date <= :2 and date >= :3', ud_key, now , start_of_week).fetch(100)
                        logging.info('got %s score entities' % len(score_entities))
                        if score_entities is not None:
                                scores = [ s.score for s in score_entities if s is not None ]
                                score=sum(scores)

                        logging.info('calculated score : %s' % score )
                        exp_ts=time.mktime((datetime.datetime.now() + datetime.timedelta(days=1)).timetuple())
                        memcache.set(memcache_key, score, time=exp_ts)
                badges = None
                all_badges = UserBadge.gql('WHERE user = :1 order by date desc', self.instaright_account).fetch(1000)
                if all_badges is not None:
                        badges = set([ (b.badge, b.badge_property.badge_desc) for b in all_badges if b is not None and b.badge_property is not None ])
                template_variables = {'user':self.screen_name, 'avatar':self.avatar,'instaright_account':self.instaright_account,'facebook_token':self.facebook_oauth_token,'facebook_profile': self.facebook_profile, 'twitter_profile': self.twitter_profile, 'twitter_token': self.twitter_oauth_token, 'google_profile': self.google_profile, 'google_token':self.google_oauth_token, 'picplz_profile': self.picplz_name, 'picplz_token': self.picplz_oauth_token, 'evernote_profile': self.evernote_name, 'evernote_token': self.evernote_oauth_token, 'links':links, 'score': score, 'visible_items_num': self.link_batch, 'badges': badges,'logout_url':'/account/logout'}
                logging.info('templates %s' %template_variables)
                path= os.path.join(os.path.dirname(__file__), 'templates/user_info.html')
                self.response.headers["Content-type"] = "text/html"
		self.response.out.write(template.render(path,template_variables))