Пример #1
0
        def get(self, user):
                if user is None or len(user) == 0:
                        logging.error('Empty user. Skipping')
                        return
                user_decoded = urllib.unquote(user)
                logging.info('user: %s' %user_decoded)
                ud=UserDetails.gql('WHERE instapaper_account = :1' , user_decoded).get()
                if ud is None:
                        logging.info('non existing user. redirect to home')
                        self.redirect('/')
                        return
                # sanity check
                if ud.instaright_account is None:
                        ud.instaright_account = ud.instapaper_account
                        ud.put()
                memcache_key ='user_info_' + user_decoded+'_'+str(datetime.datetime.now().date())
                sessions = SessionModel.gql('WHERE instaright_account = :1 ORDER by date desc ' , user_decoded).fetch(100)
                links = [ s for s in sessions if s is not None ]
                cached_info = memcache.get(memcache_key)
                if cached_info:
                        logging.info('getting from cache' )
                        template_variables = {'user':cached_info,'links':links}
                        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))
                        return
                user_detail= UserDetails.gql('WHERE mail = :1', user_decoded).get()
                if user_detail is None:
			logging.info('new user %s added to queue' %user_decoded)
			fetch_url = '/user/'+user+'/fetch'
			taskqueue.add(queue_name='user-info', url= fetch_url)
                        ud = UserDetails()
                        ud.name = user_decoded
                        ud.instapaper_account = user_decoded
                        ud.instaright_account = user_decoded
                        ud.links_added = SessionModel.countAllForUser(user_decoded)
                        # tmp put until we find more info for user
                        ud.put()
                        template_variables = {'user':ud, 'links': links}
                        path= os.path.join(os.path.dirname(__file__), 'templates/user_info.html')
                        self.response.headers["Content-type"] = "text/html"
                        self.response.headers["Accept-Charset"] = "utf-8"
		        self.response.out.write(template.render(path,template_variables))
			return
                if user_detail.instaright_account is None:
                        user_detail.instaright_account = user_decoded
                        user_detail.put()
		memcache.set(memcache_key, user_detail)
                template_variables = {'user':user_detail, "links" : links}
                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))
Пример #2
0
        def test_update_encode(self):
                e = EncodeUtils()
                ss = SessionModel.gql('ORDER by url_counter_id desc').fetch(1000)
                test = SessionModel.countAllForUser('*****@*****.**')
                logging.info('count for user  %s' % test)
                logging.info("fetch %s " %len(ss))
                for s in ss:
                        cnt = s.url_counter_id
                        encode26 = e.enbase(cnt)
                        logging.info("e26: before %s after %s" % (s.url_encode26, encode26))
                        s.url_encode26 = encode26
                        #s.put()
		self.assertEquals(True, True)