示例#1
0
 def registerUser(self, request):
     p_key = ndb.Key(UserDetails, request.phoneNumber)
     succ = 1
     user = UserDetails(
         key=p_key,
         displayName=request.displayName,
         mainEmail=request.mainEmail,
         balance=0,
         phoneNumber=request.phoneNumber,
         pin=request.pin,
         uri=request.uri,
     )
     try:
         user.put()
     except datastore_errors.DuplicatePropertyError:
         succ = 0
     prof = ProfileForm()
     if succ == 1:
         prof.displayName = user.displayName
         prof.uri = user.uri
         prof.mainEmail = user.mainEmail
         prof.balance = user.balance
         prof.phoneNumber = user.phoneNumber
     prof.success = succ
     return prof
示例#2
0
def insertDetails(request):
	if request.method == "POST":	
		uid = request.session['uID']
		name = request.POST['uname']
		add = request.POST['add']
		cty = request.POST['city']
		stat = request.POST['state']
		cntry = request.POST.get('country', False)
		pinno = request.POST['pin']
		contno = request.POST['contactno']
		res = Login.objects.get(id = uid)
		res.username = name
		res.save()
		request.session['uName'] = name
		try:
			ins = UserDetails.objects.get(uId_id = uid)
			ins.address = add
			ins.city = cty
			ins.state = stat
			ins.country = cntry
			ins.pin = pinno
			ins.contactno = contno
			ins.save()
			return render(request, 'loggedin.html', {"username" : name, "add" : add, "city" : cty, "state" : stat, "country" : cntry, 						"pin" : pinno, "contno" : contno, "status" : "Modify", "msg" : "Data Saved Successfully..."})
		except:
			ins = UserDetails(uId_id = uid, address = add, city = cty, state = stat, country = cntry, pin = pinno, contactno = contno)
			ins.save()
			return render(request, 'loggedin.html', {"username" : name, "add" : add, "city" : cty, "state" : stat, "country" : cntry, 						"pin" : pinno, "contno" : contno, "status" : "Modify", "msg" : "Data Saved Successfully..."})
	else:
		return viewDetails(request)
示例#3
0
def insertDetails(request):
    if request.method == "POST":
        uid = request.session['uID']
        name = request.POST['uname']
        add = request.POST['add']
        cty = request.POST['city']
        stat = request.POST['state']
        cntry = request.POST.get('country', False)
        pinno = request.POST['pin']
        contno = request.POST['contactno']
        res = Login.objects.get(id=uid)
        res.username = name
        res.save()
        request.session['uName'] = name
        try:
            ins = UserDetails.objects.get(uId_id=uid)
            ins.address = add
            ins.city = cty
            ins.state = stat
            ins.country = cntry
            ins.pin = pinno
            ins.contactno = contno
            ins.save()
            return render(
                request, 'loggedin.html', {
                    "username": name,
                    "add": add,
                    "city": cty,
                    "state": stat,
                    "country": cntry,
                    "pin": pinno,
                    "contno": contno,
                    "status": "Modify",
                    "msg": "Data Saved Successfully..."
                })
        except:
            ins = UserDetails(uId_id=uid,
                              address=add,
                              city=cty,
                              state=stat,
                              country=cntry,
                              pin=pinno,
                              contactno=contno)
            ins.save()
            return render(
                request, 'loggedin.html', {
                    "username": name,
                    "add": add,
                    "city": cty,
                    "state": stat,
                    "country": cntry,
                    "pin": pinno,
                    "contno": contno,
                    "status": "Modify",
                    "msg": "Data Saved Successfully..."
                })
    else:
        return viewDetails(request)
示例#4
0
        def get(self):
		users=UserDetails.gql('ORDER by __key__').fetch(100)
		if not users:
			return None
                taskqueue.add(url='/user/task/update_all', params={'users':simplejson.dumps(users, default=lambda u: {'u':u.instapaper_account})})
		lastKey = users[-1].key()
		while len(users) == 100:
			users=UserDetails.gql('WHERE __key__> :1 ORDER by __key__', lastKey).fetch(100)
			lastKey=users[-1].key()
                        taskqueue.add(url='/user/task/update_all', params={'users':simplejson.dumps(users, default=lambda u: {'u':u.instapaper_account})})
示例#5
0
 def get(self):
         prop=self.request.get('property',None)
         u = UserDetails()
         users = []
         buf = []
         if prop is not None and hasattr(u,prop):
                 logging.info('property %s' %prop)
                 if prop == 'mail':
                         logging.info('fetching users with mail')
                         users=UserDetails.gql('ORDER by mail desc').fetch(10000)
         else:
                 logging.info('missing property')
         if len(users) > 0:
                 logging.info('fetched %s' % len(users))
                 for u in users:
                         if u.mail is not None:
                                 buf.append('dn: cn='+u.name+',mail='+u.mail)
                                 buf.append('objectclass: top')
                                 buf.append('objectclass: person')
                                 buf.append('objectclass: organizationalPerson')
                                 buf.append('objectclass: inetOrgPerson')
                                 buf.append('objectclass: mozillaAbPersonAlpha')
                                 buf.append('givenName:'+u.name)
                                 buf.append('sn:')
                                 buf.append('cn:'+u.name)
                                 buf.append('mail:'+u.mail)
                                 buf.append('modifytimestamp: 0Z')
                                 buf.append('')
                         else:
                                 logging.info('missing mail %s' % u.name)
                                 
                         
                 self.response.headers['Content-type']='text/plain'
                 self.response.out.write('\n'.join(buf))
示例#6
0
 def post(self, user_account_key):
         api = twitter.Api(
                         consumer_key='WZ9re48FXCmnaNlN4rbuhg',
                         consumer_secret='jEQ7gDsE2aR9AXrA6aMZHBvKvvFgurjXoSiYLiyjQ', 
                         access_token_key='193034839-oI43CpQA6Mf1JC2no0mKwGxgT7wyWdDL6HpSKlMz', 
                         access_token_secret='q2CP7JR8wNrMNbqgRs9YezZtdMtZO7OgcgTRjCSY'
                         ) 
         #print user.screen_name
         key = db.Key(user_account_key)
         user = UserDetails.gql('WHERE __key__ = :1' , key).get()
         if user is None:
                 logging.info('no user with key %s' % user_account_key)
                 return 
         if not user.twitter or user.twitter_request_sent:
                 logging.info('user %s has not twitter account' % user.instapaper_account)
                 return
         screen_name = str(user.twitter).replace('http://twitter.com/', '')
         screen_name='bojanbabic'
         logging.info('sending request to twitter user %s ' % screen_name)
         try:
                 api.CreateFriendship(screen_name)
                 logging.info('request send succesfully to user %s' %screen_name)
         except:
                 logging.info('error sending twiter request %s, trying to resend request.' % screen_name)
                 try:
                         api.DestroyFriendship(screen_name)
                         api.CreateFriendship(screen_name)
                         logging.info('request send succesfully to user %s' %screen_name)
                 except:
                         logging.info('error resending twiter request %s' % screen_name)
         user.twitter_request_sent = True
         user.put()
示例#7
0
 def post(self):
         user_details_key=self.request.get('user_details_key',None)
         user_token=self.request.get('user_token',None)
         user_secret=self.request.get('user_secret', None)
         if user_token is None or user_secret is None:
                 logging.info('no user key or secret ... skipping ')
                 return
         userDetails=UserDetails.gql('WHERE __key__ = :1', db.Key(user_details_key)).get()
         if userDetails is None:
                 logging.info('key %s is wrong ...' % user_details_key)
                 return
         logging.info('accessing twitter api: consumer key %s consumer secret %s' %( self.instaright_consumer_key, self.instaright_consumer_secret))
         logging.info('user tokens: key %s secret %s' %( user_token, user_secret))
         api = twitter.Api(
                         consumer_key=self.instaright_consumer_key,
                         consumer_secret=self.instaright_consumer_secret,
                         access_token_key=user_token,
                         access_token_secret=user_secret
                         ) 
         try:
                 followers=api.GetFollowers()
                 u=False
                 if followers is not None:
                         userDetails.twitter_following=','.join(''.join([ u.id for u in followers ]));
                         logging.info('fetched followers for %s: %s' % userDetails.twitter, len(followers))
                         u = True
                 friends=api.GetFriends()
                 if friends is not None:
                         userDetails.twitter_following=','.join(''.join([ u.id for u in friends ]));
                         logging.info('fetched friends for %s: %s' % userDetails.twitter, len(friends))
                         u = True
                 if u == True:
                         userDetails.put()
         except:
                 logging.info('tweet friends fetchd error %s => %s' % (sys.exc_info()[0], sys.exc_info()[1]))
示例#8
0
	def test_user_token(self):
		user='******'
		ud=UserDetails.gql('WHERE instapaper_account = :1' , user).get()
		#self.assertTrue(ud is not None)
		token=UserTokens()
		#token.user_details=ud
		token.put()
示例#9
0
def get_mobile_brands_counts(request, age_range, family_monthly_income):
    print "in get mobile brands counts %s,%s" % (age_range,
                                                 family_monthly_income)
    mobile_brand_list = []
    samsung_count, nokia_count, micromax_count, lava_count = get_mobile_brands_count_model(
        age_range, family_monthly_income)
    mobile_brand_count_dict = {
        'samsung': samsung_count,
        'nokia': nokia_count,
        'micromax': micromax_count,
        'lava': lava_count
    }

    sorted_count_list = sorted(mobile_brand_count_dict.items(),
                               key=lambda x: x[1],
                               reverse=True)
    mobile_brand_count_dict = OrderedDict()
    for i in sorted_count_list:
        mobile_brand_count_dict[i[0]] = i[1]
    result = get_mobile_brands_model(age_range, family_monthly_income)
    for data in result:
        mobile_brand = UserDetails(data['_id'], data['mobile_brand'],
                                   data['name'])
        mobile_brand_list.append(mobile_brand)
    return Response(mobile_brand_count_dict)
示例#10
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))
示例#11
0
    def post(self):
        user, user_details = self.get_current_user(redirect=True)
        if not user: return

        details = UserDetails(user=user, 
                              age=int(self.request.get('AgeInYears')),
                              years_of_training=int(self.request.get('NYearsTraining')),
#                               recruited_through_sona= \
#                                 self.request.get('recruitedThroughSona') == 'True',
                              parent=ndb.Key('UserDetails', ANNOTATION_NAME))
                                
#         if self.request.get('SonaNumber'):
#             details.sona_number = int(self.request.get('SonaNumber'))
            
        details.put()

        self.redirect('/annotate?agree=/form/')
示例#12
0
文件: bot.py 项目: gulyhuli/rel
def handle_order_input_tm(message):
    if message.text:
        user_input = UserDetails.get_current_user_input(
            chat_id=message.chat.id, user=message.from_user)
        user_input.tm_name = message.text
        user_input.save()
        StepModel.set_chat_step(message.chat.id, const.Steps.order_input_email)
        bot.send_message(message.chat.id, 'Введите ваш email')
    else:
        bot.send_message(message.chat.id, 'Не понял. Введите ваш @TM')
示例#13
0
文件: bot.py 项目: gulyhuli/rel
def handle_order_input_name(message):
    if message.text:
        user_input = UserDetails.get_current_user_input(
            chat_id=message.chat.id, user=message.from_user)
        user_input.name = message.text
        user_input.save()
        StepModel.set_chat_step(message.chat.id, const.Steps.order_input_phone)
        bot.send_message(message.chat.id, 'Введите ваш телефон')
    else:
        bot.send_message(message.chat.id, 'Не понял. Введите ваше имя')
示例#14
0
 def get(self):
         tweetsSent = UserDetails.gql('WHERE twitter_request_sent = True').fetch(1000)
         if len(tweetsSent) == 0 or tweetsSent is None:
                 logging.info('no user tweeter request has been sent. exiting ')
                 return
         logging.info('requests send %d' %len(tweetsSent))
         for t in tweetsSent:
                 t.twitter_request_sent = False
                 t.put()
         logging.info('Done')
示例#15
0
 def post(self, user, form_key):
         if user is None or len(user) == 0:
                 logging.error('Empty user. Skipping')
                 return
         user_decoded = urllib.unquote(user)
         user_detail= UserDetails.gql('WHERE instapaper_account = :1 ' , user_decoded).get()
         if user_detail:
                 user_detail.form_key=form_key
                 user_detail.put()
         self.response.headers["Content-type"] = "text/plain"
         self.response.out.write(form_key)
示例#16
0
文件: bot.py 项目: gulyhuli/rel
def handle_order_input_email(message):
    if message.text:
        user_input = UserDetails.get_current_user_input(
            chat_id=message.chat.id, user=message.from_user)
        user_input.email = message.text
        user_input.save()
        bot.send_message(message.chat.id, 'Спасибо')
        send_user_details_to_admin(user_input)
        show_start_menu(message.chat.id)
    else:
        bot.send_message(message.chat.id, 'Не понял. Введите ваш email')
示例#17
0
        def get(self):
                memcache_key = 'update_user_badges'
                cached_badges = memcache.get(memcache_key)
                #if cached_badges is not None:
                #        logging.info('badge from cache')
                ##        u_badges = cached_badges
                #else:
                user_badges = UserBadge.all()
                u_badges = [ u for u in user_badges if u.badge_property is None ]
                memcache.set(memcache_key, u_badges)

                logging.info('total badges %s' % len(u_badges))
                for ub in u_badges:
                        if ub.badge_property is not None:
                                logging.info('skipping already defined badge_p')
                                continue
                        b = Badges.gql('WHERE badge_label = :1 ', ub.badge).get()
                        if b is None:
                                b = Badges()
                                b.badge_label = ub.badge
                                b.badge_icon = ub.badge
                                b.put()
                        ud = UserDetails.gql('WHERE instaright_account = :1' , ub.user).get()
                        if ud is None:
                                ud = UserDetails()
                                ud.instaright_account = ub.user
                                ud.put()
                        ub.badge_property=b.key()
                        ub.user_property = ud.key()
                        ub.put()
示例#18
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
示例#19
0
def delete(request):
    id = eval("request." + request.method + "['id']")
    if request.method == 'POST':
        post = UserDetails.objects(id=id)[0]
        post.delete()
        template = 'index.html'
        params = {'UserDetails': UserDetails.objects}
    elif request.method == 'GET':
        template = 'delete.html'
        params = {'id': id}

    return render_to_response(template,
                              params,
                              context_instance=RequestContext(request))
示例#20
0
 def get(self, empty_name):
         memcache_key = 'users_w_twitter_' + str(datetime.datetime.now().date())
         users = memcache.get(memcache_key)
         if not users:
                 all_users = UserDetails.getAll()
                 users_with_twitter = [ u for u in all_users if u.twitter is not None ] #and ((hasattr(u, 'twitter_request_sent') and u.twitter_request_sent == False) or (not hasattr(u, 'twitter_request_sent')) ]
                 memcache.set(memcache_key, users)
                 users = users_with_twitter
         if not users or len(users) == 0:
                 logging.info('currently, no users on twitter')
                 return
         logging.info('retreived %d users with twitter account' % len(users))
         for u in users:
                 taskqueue.add(url='/util/twitter/follow/'+str(u.key()), queue_name='twit-queue')
示例#21
0
def get_mobile_brands(request, age_range, family_monthly_income):
    print "in get mobile brands %s,%s" % (age_range, family_monthly_income)
    mobile_brand_list = []
    result = get_mobile_brands_model(age_range, family_monthly_income)
    for data in result:
        mobile_brand = UserDetails(data['_id'], data['mobile_brand'],
                                   data['name'])
        print mobile_brand
        mobile_brand_list.append(mobile_brand)
    print mobile_brand_list

    serialized = UserSerializer(mobile_brand_list, many=True)
    print serialized.data
    return Response(serialized.data)
示例#22
0
        def get(self, stat_range):
                format = self.request.get('format', None)
		if '-' in stat_range:
		        low, high = stat_range.split('-')
		else:
		        low, high = stat_range, None
       		memcache_key = 'top_users_' +str(datetime.datetime.now().date()) + '_' + stat_range
       		usrs = memcache.get(memcache_key)
		if usrs:
                        if format and format == 'txt':
                                self.response.headers["Content-type"] = "text/plain"
                                self.response.out.write("\n".join([u[0] for u in usrs]))
                                return 
                	template_variables = {'users': usrs}
        		path= os.path.join(os.path.dirname(__file__), 'templates/top_users.html')
                    	self.response.headers["Content-type"] = "text/html"
        		self.response.out.write(template.render(path, template_variables))
                        return
       	        elif high:
			logging.info('lower range %s ; higher range %s' %(low, high))
			users = UserDetails.gql('WHERE links_added >= :1 and links_added < :2 ORDER by links_added DESC', int(low), int(high))
		else:
			logging.info('lower range %s ' %low)
			users = UserDetails.gql('WHERE links_added >= :1 ORDER by links_added DESC', int(low))
                logging.info('fetched %d users ' % users.count())
	       	user_accounts = [ (u.instapaper_account, u.links_added) for u in users ]
		if users.count() > 0:
			logging.info('setting users cache. %s user entries' % users.count())
        		memcache.set(memcache_key, user_accounts)
                if format and format == 'txt':
                        self.response.headers["Content-type"] = "text/plain"
                        self.response.out.write("\n".join([ u[0] for u in user_accounts ]))
                        return
                template_variables = {'users' : user_accounts }
		path= os.path.join(os.path.dirname(__file__), 'templates/top_users.html')
        	self.response.headers["Content-type"] = "text/html"
		self.response.out.write(template.render(path,template_variables))
示例#23
0
        def getAvatar(cls,instapaper_account):
                if instapaper_account is None:
                        return '/static/images/noavatar.png'
		memcache_key='avatar_'+instapaper_account
		cached_avatar = memcache.get(memcache_key)
		if cached_avatar:
                        logging.info('getting avatar from cache: %s for user %s' %(cached_avatar, instapaper_account))
			return cached_avatar
		userDetails = UserDetails.gql('WHERE instapaper_account = :1', instapaper_account).get()
		if userDetails and userDetails.avatar is not None:
                        logging.info('%s avatar %s' % (instapaper_account, userDetails.avatar))
			memcache.set(memcache_key, userDetails.avatar)
			return userDetails.avatar
		else:
			return '/static/images/noavatar.png'
示例#24
0
 def googleLoginUser(self, request):
     qry = UserDetails.GoogleLogin(request.mainEmail, request.uri)
     succ = 1
     user = qry.get()
     prof = ProfileForm()
     if user is None:
         succ = 0
     elif succ == 1:
         prof.displayName = user.displayName
         prof.mainEmail = user.mainEmail
         prof.phoneNumber = user.phoneNumber
         prof.balance = user.balance
         prof.uri = user.uri
     prof.success = succ
     return prof
示例#25
0
 def restore_object(self, attrs, instance=None):
     if instance:
         instance.id = attrs.get('id', instance.id)
         instance.state = attrs.get('state', instance.state)
         instance.city = attrs.get('city', instance.city)
         instance.geography = attrs.get('geography', instance.geography)
         instance.name = attrs.get('name', instance.name)
         instance.address = attrs.get('address', instance.address)
         instance.phone_no = attrs.get('phone_no', instance.phone_no)
         instance.family_members_count = attrs.get(
             'family_members_count', instance.family_members_count)
         instance.age_range = attrs.get('age_range', instance.age_range)
         instance.gender = attrs.get('gender', instance.gender)
         instance.family_income_range = attrs.get(
             'family_income_range', instance.family_income_range)
         instance.caste = attrs.get('caste', instance, caste)
         instance.occupation = attrs.get('occupation', instance.occupation)
         instance.monthly_recharge = attrs.get('monthly_recharge',
                                               instance.monthly_recharge)
         instance.data_usage = attrs.get('data_usage', instance.data_usage)
         instance.hospital = attrs.get('hospital', instance.hospital)
         instance.laptop = attrs.get('laptop', instance.laptop)
         instance.school = attrs.get('school', instance.school)
         instance.fb_account = attrs.get('fb_account', instance.fb_account)
         instance.whatsapp_account = attrs.get('whatsapp_account',
                                               instance.whatsapp_account)
         instance.email_id = attrs.get('email_id', instance.email_id)
         instance.mobile_brand = attrs.get('mobile_brand',
                                           instance.mobile_brand)
         instance.mobile_network = attrs.get('mobile_network',
                                             instance.mobile_network)
         return instance
     return UserDetails(attrs.get('id'), attrs.get('state'),
                        attrs.get('city'), attrs.get('geography'),
                        attrs.get('name'), attrs.get('address'),
                        attrs.get('phone_no'),
                        attrs.get('family_members_count'),
                        attrs.get('age_range'), attrs.get('gender'),
                        attrs.get('caste'),
                        attrs.get('family_income_range'),
                        attrs.get('occupation'), attrs.get('data_usage'),
                        attrs.get('hospital'), attrs.get('laptop'),
                        attrs.get('school'), attrs.get('fb_account'),
                        attrs.get('whatsapp_account'),
                        attrs.get('email_id'), attrs.get('mobile_brand'),
                        attrs.get('mobile_network'))
示例#26
0
	def getKloutScore(cls, user, klout_api_key):
		score = None
		logging.info('klout score for %s' % user)
		userDetails=UserDetails.gql('WHERE instapaper_account = :1' , user).get()
		if userDetails is None or userDetails.twitter is None:
                	logging.info(' trying get more info for user %s' % user)
                	userDetails = UserUtils.gather_info(user)
			if userDetails is not None:
				logging.info('saving user info %s' %userDetails.mail)
			        try:
				        while True:
					        timeout_ms = 100
					        try:
				                        userDetails.put()
						        break
					        except datastore_errors.Timeout:
						        time.sleep(timeout_ms)
						        timeout_ms *= 2
			        except apiproxy_errors.DeadlineExceededError:
				        logging.info('run out of retries for writing to db')
		if userDetails is None or userDetails.twitter is None:
			logging.info('no twitter account for user %s . aborting' % user)
			return
			
                screen_name = str(userDetails.twitter).replace('http://twitter.com/', '')
		KLOUT_SCORE_URL='http://api.klout.com/1/klout.json?key=%s&users=%s' %(klout_api_key, screen_name)
		response = None
		try:
                        response = urlfetch.fetch(KLOUT_SCORE_URL)
		except:
			logging.info('error fetching url %s' % KLOUT_SCORE_URL)
		if response is None or response.status_code != 200:
               		logging.info('unexpected response') 
			return
		logging.info('klout api response %s' % response.content)
		json = eval(response.content)
		try:
			score = json["users"][0]["kscore"]
			logging.info('klout api returned score %s for user %s' % ( str(score), screen_name))
		except:
                        e, e1 = sys.exc_info()[0], sys.exc_info()[1]
                        logging.info('error: %s, %s for response: %s' %(e, e1, json))
		if score is not None:
			userDetails.klout_score=int(score)
			userDetails.put()
		return score
示例#27
0
def index(request):
    if request.method == 'POST':
        # save new post
        username = request.POST['username']
        password = request.POST['password']
        address = request.POST['address']

        post = UserDetails(username=username)
        post.password = password
        post.last_update = datetime.datetime.now()
        post.address = address
        post.save()

    # Get all posts from DB
    posts = UserDetails.objects
    return render_to_response('index.html', {'UserDetails': posts},
                              context_instance=RequestContext(request))
示例#28
0
def update(request):
    id = eval("request." + request.method + "['id']")
    post = UserDetails.objects(id=id)[0]

    if request.method == 'POST':
        # update field values and save to mongo
        post.username = request.POST['username']
        post.password = request.POST['password']
        post.last_update = datetime.datetime.now()
        post.address = request.POST['address']
        post.save()
        template = 'index.html'
        params = {'UserDetails': UserDetails.objects}

    elif request.method == 'GET':
        template = 'update.html'
        params = {'post': post}

    return render_to_response(template,
                              params,
                              context_instance=RequestContext(request))
示例#29
0
    def get(self):
        user, user_details = self.get_current_user(True, True)
        if not user: return
        
        if "dump" in self.request.arguments():
            contents, subcontents, ratings, _counts = \
                self.get_contents(get_ratings=True, get_ratings_count=False)
                
            output = {"content": []}
            for content in contents:
                output['content'].append(content.to_dict())
                if content.key.urlsafe() in ratings:
                    output['content'][-1]['ratings'] = \
                        [rating.to_dict() for rating in ratings[content.key.urlsafe()]]
                if content.key.urlsafe() in subcontents:
                    output['content'][-1]['subcontents'] = []
                    for subcontent in subcontents[content.key.urlsafe()]:
                        output['content'][-1]['subcontents'].append(subcontent.to_dict())
                        if subcontent.key.urlsafe() in ratings:
                            output['content'][-1]['subcontents'][-1]['ratings'] = \
                                [rating.to_dict() for rating in ratings[subcontent.key.urlsafe()]]
            users = UserDetails.query(ancestor=\
                            ndb.Key('UserDetails', ANNOTATION_NAME)).fetch()
            output["users"] = map(lambda user_detail: user_detail.to_dict(), users)
                
            self.response.headers.add_header("Content-type", "text/x-yaml")
            self.response.write(yaml.dump(output))
        else:
            contents, subcontents, _ratings, counts = self.get_contents()

            template_values = {
                "contents": contents,
                "counts": counts,
                "subcontents": subcontents,
            }
            
            self.template_response('admin.html', template_values)
示例#30
0
def save_profile_to_db(uid, details):
    t0 = time.time()
    print('Saving profile for user: %s' % str(uid))

    try:
        user_details = DBSession.query(UserDetails).filter(
            UserDetails.uid == uid)
        if user_details is not None and user_details.count() == 1:
            print('Profile already exists in DB')
        else:
            name = details.get('UserName', None)
            gender = details.get('Gender', '')
            age = details.get('Age', '')
            religion = details.get('Religion', '')
            marital_status = details.get('Marital Status', '')
            occupation = details.get('Profession', '')
            education = details.get('Education', '')

            user_details = UserDetails(name=name,
                                       gender=gender,
                                       age=age,
                                       religion=religion,
                                       marital_status=marital_status,
                                       occupation=occupation,
                                       education=education,
                                       uid=uid)
            DBSession.add(user_details)
            DBSession.commit()
            # user_id = user_details.id
    except Exception as e:
        print('Exception saving user-profile details: %s. Error: %s' %
              (uid, str(e)))
        DBSession.rollback()

    print("SQLAlchemy ORM: Total time for saving user details for uid: " +
          str(uid) + " = " + str(time.time() - t0) + " secs")
示例#31
0
        def post(self):
                user=self.request.get('user', None)
                url=self.request.get('url', None)
                domain=self.request.get('domain', None)
                version=self.request.get('version', None)
                client=self.request.get('client', None)
                badge=None
                if user is None:
                        logging.info('unknown user skipping')
                        return
                user_details = UserDetails.gql('WHERE instaright_account = :1', user).get()
                if user_details is None:
                        user_details = UserDetails()
                        user_details.instaright_account = user
                        user_details.put()
                client_badge = UserBadge.gql('WHERE badge = :1 and user = :2', client, user).get()
                if client_badge is None:
                        badge = Badges.gql('WHERE badge_label = :1' , client).get()
			if badge is None:
                        	mail.send_mail(sender='*****@*****.**', to='*****@*****.**', subject='Unknown client!', html='user %s saved link %s using unrecognised client %s' %( user,url, client ), body='user %s saved link %s using unrecognised client %s' %( user,url, client))
				return
                        client_badge = UserBadge()
                        client_badge.badge = client
                        client_badge.badge_property = badge.key()
                        client_badge.date = datetime.datetime.now().date()
                        client_badge.user = user
                        client_badge.user_property = user_details.key()
                        client_badge.put()
                if version is not None and len(version) == 0:
                        version = None
                currentBadge = memcache.get('badge_'+user)
                if currentBadge is not None and (currentBadge == '1' or currentBadge == '2' or currentBadge == '3' or currentBadge == '5'):
                        logging.info('for user %s already using full day badge: %s' %(user,currentBadge))
                        return
                badger=BadgeUtil.getBadger(user, url, domain, version)
                if badger is None:
                        logging.info('no badger initialized. skipping')
                        return
                badge=badger.getBadge()
                if badge is not None:
                        # midnight timestamp - memcache expiration 
                        midnight=datetime.datetime.now().date() + datetime.timedelta(days=1)
                        midnight_ts=time.mktime(midnight.timetuple())
                        memcache.set('badge_'+user, badge, time=midnight_ts)
                        logging.info('setting badge cache: %s for user badge_%s valid until midnight %s' % (badge,user,midnight_ts))
                        existingBadge=UserBadge.gql('WHERE badge = :1 and user = :2 and date = :3', badge, user, datetime.datetime.now().date()).get()
                        if existingBadge is not None:
                                self.response.out.write('request processed')
                                return
                        b = Badges.gql('WHERE badge_label = :1' , badge).get()
                        if b is None:
                                b = Badges()
                                b.badge_label = badge
                                b.badge_icon = badge
                                b.put()
                        userBadge=UserBadge()
                        userBadge.user=user
                        userBadge.badge=badge
                        userBadge.badge_property = b.key()
                        userBadge.user_property = user_details.key()
                        userBadge.put()
			
                UserScoreUtility.updateBadgeScore(user, badge)
示例#32
0
 def get(self):
         user_details =  UserDetails.all()
         logging.info('fetched %d ' % user_details.count())
         for u in user_details:
                 logging.info('deleting %s' %(u.instapaper_account))
                 u.delete()
示例#33
0
        def gather_info(self, user):
                if not '@' in user:
			logging.info('not email address: skipping ...')
                        user_detail = UserDetails()
			return user_detail
                user_detail = UserDetails.gql('where instapaper_account = :1' , user).get()
		if user_detail is None:
			user_detail = UserDetails()
		if user_detail.mail is None:
			logging.info('updating user details setting user mail %s' % user)
			user_detail.mail = user
                if user_detail.instaright_account is None:
                        logging.info('update instaright account for user %s' % user)
                        user_detail.instaright_account = user

                #PREPARE for request
                #time_milis = time.time() * 1000
                logging.info("user encoded %s" % user)
                RAPPORTIVE_LINK = "https://rapportive.com/contacts/email/%s" % user
		logging.info('fetchin url:%s' %RAPPORTIVE_LINK)
		#TILL here
                try:
                        response = urlfetch.fetch(RAPPORTIVE_LINK)
                except:
                        logging.info('error downloading rapportive info. reTRYing')
			try:
                        	response = urlfetch.fetch(RAPPORTIVE_LINK)
			except:
                        	e, e1 = sys.exc_info()[0], sys.exc_info()[1]
                        	return user_detail
                if response.status_code == 200:

                        json_string_response = simplejson.loads(simplejson.dumps(response.content))
                        json = simplejson.loads(json_string_response)
			name = None
			try:
                        	name = json["contact"]["name"]
			except:
				logging.info("unable to gather name from rapportive")

                        if name is None or len(name) < 1 or unicode(name).startswith('Thanks') or unicode(name).startswith('Sorry'):
				logging.info('did not find name for account %s' % user)
                                return user_detail
                        
                        logging.info('name: %s' % unicode(name))
                        user_detail.name = unicode(name)
                        memberships = json["contact"]["memberships"] 
                        memships = {}
                        for m in memberships:
                                service_name = m['site_name'].lower().replace(' ','_').replace('.','_')
                                memships[service_name]=m['profile_url']
				try:
                                	setattr(user_detail, service_name, m['profile_url'])
					logging.info('service %s profile %s' % (service_name, m['profile_url']))
                                        if service_name == 'twitter' and not user_detail.twitter_request_sent:
                                                # send twitter request and need to put since we need key for follow
						user_detail.twitter_request_sent=True
						user_detail.put()
                                                taskqueue.add(url='/util/twitter/follow/'+str(user_detail.key()), queue_name='twit-queue')
				except:
					logging.error('memberships error %s ::: more details %s ' % (sys.exc_info()[0], sys.exc_info()[1]))

                        user_detail.social_data = simplejson.dumps(memships)
                        occupations = json["contact"]["occupations"]
                        occups = []
                        for o in occupations:
                                tmp_o = o['job_title'] + " ^_^ " + o['company']
                                occups.append(tmp_o)
                        user_detail.occupations = '; '.join(occups)
			logging.info('occupations %s' %user_detail.occupations)
			avatar = None
			try:
                        	avatar = json["contact"]["images"][0]["url"]
                        	logging.info('avatar %s' % avatar)
			except:
				logging.info('no image info cause of %s' % sys.exc_info()[0])
                        if avatar is not None and len(avatar) > 0:
                                user_detail.avatar = avatar
			location = None
			try:
				location = json["contact"]["location"]
			except:
				logging.info('no location info cause of %' %sys.exc_info()[0])
			if location is not None and len(location):
				location_lines = location.splitlines()
				user_detail.location = ' '.join(location_lines)
                return user_detail
示例#34
0
	def getUserDetails(self, request_handler):
		
		#google_login_url = users.create_login_url('/') 
	        #twitter_logout_url = '/oauth/twitter/logout'

                twitter_cookie = request_handler.request.cookies.get('oauth.twitter')
        	evernote_user = OAuthClient('evernote', request_handler)
        	flickr_user = OAuthClient('flickr', request_handler)

                #return variables
        	screen_name=None
                avatar=None
		auth_service=None
		user_details_key=None

                instaright_account=None
		# used to connect user details with session
                evernote_username=None
                flickr_username=None

		google_user = users.get_current_user()
		#logging.info('trying to connect with fb key %s secret %s' %( self.facebook_key, self.facebook_secret))
        	facebook_user = facebook.get_user_from_cookie(request_handler.request.cookies, self.facebook_key, self.facebook_secret)
                facebook_access_token=None
                existing_user = None
        	if google_user:
			existing_user= UserDetails.gql('WHERE google_profile=\'%s\'' %google_user.email()).get()
			existing_user_by_mail = UserDetails.gql('WHERE mail=\'%s\'' %google_user.email()).get()
                        if self.ud is None and existing_user is not None:
                                self.ud = existing_user
                                if self.ud.mail is None:
                                        self.ud.mail = google_user.email()
                        #TODO what is both are not None and pointing to different entities
                        if existing_user is not None and existing_user_by_mail is not None and str(existing_user.key()) != str(existing_user_by_mail.key()):
                                logging.error('data inconsistancy for google user %s ' % google_user.email())
                        #NOTE: data consistency 
			if existing_user is None and existing_user_by_mail is not None:
                                existing_user_by_mail.google_profile = google_user.email()
                                existing_user_by_mail.put()
                                existing_user = existing_user_by_mail
                        if existing_user is None:
                                #TODO update google profile
				existing_user = UserDetails()
				existing_user.mail=google_user.email()
                                existing_user.google_profile=google_user.email()
                        elif existing_user.avatar is not None:
                                avatar = existing_user.avatar
				existing_user.mail=google_user.email()
                        existing_user.put()

			auth_service='google'
                	screen_name=google_user.nickname()
			user_details_key=existing_user.key()

			user_signup_badge = UserBadge.gql('WHERE user_property = :1 and badge = :2', existing_user.key(),'signup').get()
                        if user_signup_badge is None:
                                user_badge = UserBadge()
                                user_badge.user = screen_name
                                user_badge.badge = 'signup'
                                badge = Badges.gql('WHERE badge_label = :1', 'signup').get()
                                user_badge.badge_property = badge.key()
                                user_badge.user_property = existing_user.key()
                                user_badge.put()
                        instaright_account=existing_user.instaright_account
                if twitter_cookie is not None and len(twitter_cookie) > 0:
			try:
                        	twitter_user = OAuthClient('twitter', request_handler)
				info = twitter_user.get('/account/verify_credentials')
				profile_image_url = "%s" %info['profile_image_url']
				existing_user = UserDetails.gql('WHERE twitter = \'http://twitter.com/%s\'' % screen_name).get()
				if existing_user is None:
					logging.info('new twitter user login %s' % screen_name)
					existing_user=UserDetails()
					existing_user.twitter='http://twitter.com/%s' %screen_name
					existing_user.avatar = profile_image_url
				else:
					logging.info('existing twitter user login %s' % screen_name)
					if existing_user.avatar is None:
						existing_user.avatar = profile_image_url
                                        else:
                                                avatar = existing_user.avatar
                                existing_user.put()
				user_details_key=existing_user.key()
                                twitter_cookie = request_handler.request.cookies.get('oauth.twitter')
                                twitter_oauth = OAuthAccessToken.get_by_key_name(twitter_cookie)
                                if twitter_oauth is not None and existing_user is not None:
                                        twitter_token = twitter_oauth.oauth_token
                                        twitter_secret= twitter_oauth.oauth_token_secret
                                        taskqueue.add(url='/util/twitter/get_friends', params={'user_details_key': str(existing_user.key()),'user_token':twitter_token, 'user_secret': twitter_secret})
                                if screen_name is None:
                		        screen_name = "%s" % info['screen_name']
                                        avatar=profile_image_url
				        auth_service='twitter'
                                logging.info('updating user score ...')
			        user_signup_badge = UserBadge.gql('WHERE user_property = :1 and badge = :2', existing_user.key(),'signup').get()
                                if user_signup_badge is None:
                                        user_badge = UserBadge()
                                        user_badge.user = screen_name
                                        user_badge.badge = 'signup'
                                        badge = Badges.gql('WHERE badge_label = :1', 'signup').get()
                                        user_badge.badge_property = badge.key()
                                        user_badge.user_property = existing_user.key()
                                        user_badge.put()
                                instaright_account=existing_user.instaright_account
			except:
				e0,e = sys.exc_info()[0], sys.exc_info()[1]
                                logging.info('got error while using twitter oauth: %s => %s' %(e0, e))
        	if facebook_user:
                	graph = facebook.GraphAPI(facebook_user["access_token"])
			try:
                		profile = graph.get_object("me")
				profile_link=profile["link"]
				profile_id=profile["id"]
                		friends = graph.get_connections("me", "friends")
				existing_user=UserDetails.gql('WHERE facebook = \'%s\'' % profile_link).get()
				if existing_user is not None:
					logging.info('existing facebook logging %s' % profile_link)
					existing_user.facebook=profile_link
					existing_user.facebook_friends=simplejson.dumps(friends)
					existing_user.facebook_profile=profile["name"]
					existing_user.facebook_id=profile_id
					if existing_user.avatar is None:
						existing_user.avatar = avatar
                                        else:
                                                avatar = existing_user.avatar
					existing_user.put()
				else:
					logging.info('new facebook logging %s' % profile_link)
					existing_user=UserDetails()
					existing_user.facebook=profile_link
					existing_user.facebook_profile=profile["name"]
					existing_user.facebook_friends=simplejson.dumps(friends)
					existing_user.facebook_id=profile_id
					existing_user.avatar = avatar
					existing_user.put()
                                if screen_name is None:
                		        screen_name = profile["name"]
				        auth_service='facebook'
                                        avatar=existing_user.avatar
				user_details_key=existing_user.key()
			        user_signup_badge = UserBadge.gql('WHERE user_property = :1 and badge = :2', existing_user.key(),'signup').get()
                                if user_signup_badge is None:
                                        user_badge = UserBadge()
                                        user_badge.user = screen_name
                                        user_badge.badge = 'signup'
                                        badge = Badges.gql('WHERE badge_label = :1', 'signup').get()
                                        user_badge.badge_property = badge.key()
                                        user_badge.user_property = existing_user.key()
                                        user_badge.put()
                                instaright_account=existing_user.instaright_account
                                facebook_access_token=facebook_user["access_token"]
			except:
				e0,e = sys.exc_info()[0], sys.exc_info()[1]
				logging.info('error validating token %s === more info: %s' %(e0,e))
		
                if evernote_user.get_cookie() is not None and len(evernote_user.get_cookie()) > 0:
                        logging.info('evernote token active: %s' % evernote_user)
                        logging.info('evernote access token id: %s' % evernote_user.get_cookie())
                        evernote_access = evernote_user.get_cookie()
                        access_token = OAuthAccessToken.get_by_key_name(evernote_access)
                        if access_token is not None and access_token.service == 'evernote':
                                evernote_username = access_token.specifier
                                if existing_user is not None:
                                        existing_user.evernote_profile = evernote_username
                                        existing_user.put()
                        
                if flickr_user.get_cookie() is not None and len(flickr_user.get_cookie()) > 0:
                        logging.info('flickr token active: %s' % flickr_user)
                        logging.info('flickr access token id: %s' % flickr_user.get_cookie())
                        flickr_access = flickr_user.get_cookie()
                        access_token = OAuthAccessToken.get_by_key_name(flickr_access)
                        if access_token is not None and access_token.service == 'flickr':
                                flickr_username = access_token.specifier
                                if existing_user is not None:
                                        existing_user.flickr_profile = flickr_username
                                        existing_user.put()

		log_out_cookie = request_handler.request.cookies.get('user_logged_out')
		path=request_handler.request.path
		logging.info('path: %s' %path)
		#reset logout cookie in case of /account url
		if log_out_cookie and path == '/account':
			logging.info('deleting logout cookie')
                        expires = datetime.datetime.now()
                        exp_format = datetime.datetime.strftime(expires, '%a, %d-%b-%Y %H:%M:%S GMT')
			request_handler.response.headers.add_header('Set-Cookie', 'user_logged_out=%s; expires=%s; path=/' %( '0', exp_format))
			
		logging.info('user auth with %s: %s' %(auth_service, screen_name))
                if screen_name is not None and screen_name not in self.skip_list:
                        logging.info('user %s not in skip list %s ... sending mail' %(screen_name, str(self.skip_list)))
                        mail.send_mail(sender='*****@*****.**', to='*****@*****.**', subject='User sign up!', html='Awesome new user(%s) signed up: %s <br>avatar <a href="%s"><img src="%s" width=20 height=20 /></a>' %(auth_service, screen_name , avatar, avatar), body='Awesome new user(%s) signed up: %s avatar %s' %(auth_service, screen_name, avatar))
                                        
                user_details = {'screen_name':screen_name, 'auth_service':auth_service, 'user_details_key':user_details_key, 'avatar':avatar, 'instaright_account':instaright_account,'facebook_access_token': facebook_access_token, 'evernote_name': evernote_username, 'flickr_name': flickr_username}
		logging.info('[utils] user details:%s' % user_details)
		return user_details
示例#35
0
    def post(self):
        dt = self.request.get("date", None)
        cursor = self.request.get("last_cursor", None)
        logging.info("date from request %s " % dt)
        if dt is None:
            date = datetime.datetime.now().date() - datetime.timedelta(days=1)
            logging.info("aggregatine users from yesterday.")
        else:
            date = datetime.datetime.strptime(dt, "%Y-%m-%d").date()
        if date >= datetime.datetime.now().date():
            logging.info("too early , wait")
            self.response.out.write("too early . wait")
            return
        memcache_key_sessions = (
            "sessions_for_date_" + str(datetime.datetime.today().date()) + "_" + str(date) + "_" + str(cursor)
        )
        cached_sessions = memcache.get(memcache_key_sessions)
        if cached_sessions:
            logging.info("getting from cache for date %s" % str(date))
            sessions = cached_sessions
        else:
            sessions = SessionModel.getDailyDataWithOffset(date, cursor)
            logging.info("session batch size %d" % len(sessions))
            memcache.set(memcache_key_sessions, sessions)
        if sessions is None:
            logging.info("no sessions for date %s" % str(date))
            return
        for s in sessions:
            memcache_key_s = "user_detail_" + str(datetime.datetime.now().date()) + "_" + str(date) + "_" + str(s.key())
            if memcache.get(memcache_key_s):
                logging.info("skippin processed key %s for date %s" % (s.key(), str(date)))
                continue
            # links stats add to queue
            taskqueue.add(
                queue_name="data-consolidation",
                url="/aggregate_data",
                params={"sessionKey": s.key(), "upper_limit_date": date},
            )
            # TODO also create tas cue for user consolidation
            userStats = UserStats.gql("WHERE instapaper_account = :1 and date = :2", s.instaright_account, date).get()
            if userStats is None:
                logging.info("no user stats for user: %s and date: %s" % (s.instaright_account, str(date)))
                userStats = UserStats()
                userStats.instapaper_account = s.instaright_account
                userStats.count = 1
                userStats.date = date
                userStats.put()
            else:
                logging.info("updating user stats for user %s and date %s" % (s.instaright_account, str(date)))
                userStats.count = userStats.count + 1
                userStats.put()

            user_detail = UserDetails.gql("WHERE instapaper_account = :1", s.instaright_account).get()
            if user_detail is None:
                logging.info("new user: %s" % s.instaright_account)
                user_detail = UserDetails()
                user_detail.instapaper_account = s.instaright_account
                user_detail.last_active_date = s.date
                user_detail.put()
                # task queue that gathers info
                try:
                    fetch_task_url = "/user/" + urllib2.quote(s.instaright_account) + "/fetch"
                except:
                    logging.warn("can't fetch info for user %s " % s.instaright_account)
                logging.info("adding task on url %s" % fetch_task_url)
                taskqueue.add(queue_name="user-info", url=fetch_task_url)
            else:
                logging.info("updating usage for user: %s" % s.instaright_account)
                user_detail.last_active_date = s.date
                user_detail.links_added = user_detail.links_added + 1
                user_detail.put()
            memcache.set(memcache_key_s, s.key())
            # IMPORTANT:delete daily badges for user
            memcache.delete("badge_" + s.instaright_account)
        logging.info("done for date %s" % str(date))
        self.response.out.write("done for date %s" % str(date))
示例#36
0
        def get_user(self):
		uu = UserUtils()
		userSession = None
		self.screen_name=None
		self.auth_service=None
                self.avatar=None
                self.user_uuid=None
                self.instaright_account=None
                self.user_detail_key=None
                self.facebook_profile = None
                self.facebook_oauth_token = None
                self.twitter_profile = None
                self.twitter_oauth_token = None
                self.google_profile = None
                self.google_oauth_token = None
                self.evernote_name = None
                self.evernote_oauth_token = None
                self.flickr_name = None
                self.flickr_oauth_token = None
		self.picplz_name = None
		self.picplz_oauth_token = None
                self.ud=None
                ud_modified=None
                new_session=False

		uuid_cookie = self.request.cookies.get('user_uuid')
                evernote_cookie = self.request.cookies.get('oauth.evernote')
                twitter_cookie = self.request.cookies.get('oauth.twitter')
                flickr_cookie = self.request.cookies.get('oauth.flickr')
                picplz_cookie = self.request.cookies.get('oauth.picplz')
		logout_cookie = self.request.cookies.get('user_logged_out')
                user_details=None
		# try to get user name by cookie or from login
		if uuid_cookie:
			#Connect uuid with registered user
			logging.info('reusing uuid: %s' % uuid_cookie)
			self.user_uuid = uuid_cookie
			userSession = UserSessionFE.gql('WHERE user_uuid = :1 order by last_updatetime desc' , self.user_uuid).get()
			if userSession is not None and userSession.user_details is not None:
				self.ud = UserDetails.gql('WHERE __key__ = :1', userSession.user_details).get()

                                #fix instaright_account TODO possibly deprecated
                                if self.ud is not None and self.ud.instapaper_account is not None:
                                        self.ud.instaright_account=self.ud.instapaper_account
                                        ud_modified=True
				if self.ud is None:
					logging.error('missing proper db entry for cookie %s' % uuid_cookie)
				else:
					user_data = self.ud.getUserInfo()
                                        self.facebook_profile = self.ud.facebook_profile
                                        self.twitter_profile = self.ud.twitter
                                        self.google_profile = self.ud.google_profile
                                        self.evernote_name = self.ud.evernote_profile
                                        self.flickr_name = self.ud.flickr_profile
					self.screen_name = user_data["screen_name"]
                                        self.avatar = user_data["avatar"]
                                        self.instaright_account=self.ud.instaright_account
                                        self.user_detail_key=str(self.ud.key())
					logging.info('using screen name %s from session %s' %(self.screen_name, self.user_uuid))
                        if userSession is not None and userSession.user_details is None:
                                logging.info('user details not defined for session ... need to fix this with oauth')
			# sanity check
			if userSession is None:
				logging.info('smth wicked ')
				userSession = UserSessionFE()
                        if userSession and userSession.user_uuid is None:
                                userSession.user_uuid = str(self.user_uuid)
		else:
                        new_session=True
			self.user_uuid = uuid.uuid4()
			logging.info('generated new uuid: %s' % self.user_uuid)
                        expires = datetime.datetime.now() + datetime.timedelta(minutes=60)
                        exp_format = datetime.datetime.strftime(expires, '%a, %d-%b-%Y %H:%M:%S GMT')
                        logging.info('expr date %s' %exp_format)
			self.response.headers.add_header('Set-Cookie', 'user_uuid=%s; expires=%s; path=/' %( self.user_uuid, exp_format))

			userSession = UserSessionFE()
			userSession.user_uuuid = str(self.user_uuid)

		# not pretty but working
		if logout_cookie:
			logging.info('found logout cookie. reseting screen_name')
			self.screen_name = None
                        self.instaright_account=None
		else:
			user_details = uu.getUserDetails(self)
                        if user_details["screen_name"] is not None:
			        self.screen_name = user_details["screen_name"]
                        if user_details["avatar"] is not None:
                                self.avatar = user_details["avatar"]
                        if user_details["auth_service"] is not None:
			        self.auth_service = user_details["auth_service"]
                        if user_details["user_details_key"] is not None:
                                #NOTE: it is very important to set user details key!!!!
			        user_details_key = user_details["user_details_key"]
			        userSession.user_details = user_details_key
                                self.user_detail_key=str(user_details["user_details_key"])
                                #if ud changed? what then?
                                if self.ud is None:
                                        ud = UserDetails.gql('WHERE __key__ = :1' , db.Key(self.user_detail_key)).get()
                                        self.ud = ud
                        if user_details["instaright_account"] is not None:
                                self.instaright_account=user_details["instaright_account"]
                        if user_details["evernote_name"] is not None:
                                self.evernote_name = user_details["evernote_name"]
                        if user_details["flickr_name"] is not None:
                                self.flickr_name = user_details["flickr_name"]

			userSession.active=True
			
		userSession.screen_name = self.screen_name
		userSession.auth_service = self.auth_service

                #determine path
                url=self.request.url
                scheme, netloc, path, query, fragment = urlparse.urlsplit(url)

                existingUserPathSession=UserSessionFE.gql('WHERE user_uuid = :1 and path = :2 and screen_name = :3' , userSession.user_uuid, path, userSession.screen_name).get()
                if existingUserPathSession is None:
                        logging.info('new path %s -> %s' %(userSession.path, path))
                        newPathUserSession=UserSessionFE()
                        newPathUserSession.active=userSession.active
                        newPathUserSession.auth_service=userSession.auth_service
                        newPathUserSession.screen_name=userSession.screen_name
                        newPathUserSession.user=userSession.user
                        newPathUserSession.user_details=userSession.user_details
                        newPathUserSession.user_uuid=userSession.user_uuid
                        newPathUserSession.path=path
                        newPathUserSession.put()
		#userSession.put()

                user_token=None
                if self.ud is not None:
                        user_token=UserTokens.gql('WHERE user_details = :1', self.ud.key()).get()
                if user_token is None:
                        user_token=UserTokens()

		#token=UserTokens()
		#token.user_details = userSession.user_details
		#token.picplz_token= '1|oauth_secret=UxY3gF4CXmRt3tYqgYg4Ed49YbZLGuDx&oauth_token=dNyt8uanrG9sRXBse6P7uaPyZSDpwK26'
		#token.google_token= 'google|oauth_secret=UxY3gF4CXmRt3tYqgYg4Ed49YbZLGuDx&oauth_token=dNyt8uanrG9sRXBse6P7uaPyZSDpwK26'
		#token.put()

                user_token_modified=False
                evernote_oauth = None
                #NOTE: ud can be null on visits that include no auth
                if evernote_cookie is not None:
                        evernote_oauth = OAuthAccessToken.get_by_key_name(evernote_cookie)
                if evernote_oauth is not None and self.ud is not None:
                        evernote_token = evernote_oauth.oauth_token
                        logging.info('User Details modified ... updating evetnote token')
                        user_token.evernote_token=evernote_token
                        user_token.evernote_additional_info=evernote_oauth.additional_info
                        user_token_modified=True
			#TODO remove cookie -> after write not needed any more
                twitter_oauth = None
                if twitter_cookie is not None:
                        logging.info('twitter cookie defined %s' % twitter_cookie)
                        twitter_oauth = OAuthAccessToken.get_by_key_name(twitter_cookie)
                if twitter_oauth is not None and self.ud is not None:
                        twitter_token = twitter_oauth.oauth_token
                        twitter_secret= twitter_oauth.oauth_token_secret
                        logging.info('User Details modified ... updating twitter token')
                        user_token.twitter_token=twitter_token
                        user_token.twitter_secret=twitter_secret
                        user_token_modified=True
                        logging.info('twitter promo sent? %s' % self.ud.twitter_promo_sent)
                        if self.ud.twitter_promo_sent == False:
                                taskqueue.add(url='/service/submit/twitter/promo', params={'user_token': twitter_token, 'user_secret': twitter_secret, 'user_details_key': str(self.ud.key())})
                                self.ud.twitter_promo_sent=True
                                ud_modified=True
                picplz_oauth = None
                if picplz_cookie is not None:
                        picplz_oauth = OAuthAccessToken.get_by_key_name(picplz_cookie)
                        logging.info('picplz cookie defined %s' % picplz_cookie)
                if picplz_oauth is not None:
                        picplz_token = picplz_oauth.oauth_token
                        user_token.picplz_token = picplz_token
                        user_token_modified=True
			#TODO remove cookie -> after write not needed any more
                flickr_oauth = None
                if flickr_cookie is not None:
                        flickr_oauth = OAuthAccessToken.get_by_key_name(flickr_cookie)
                        logging.info('flickr cookie defined %s' % flickr_cookie)
                if flickr_oauth is not None and self.ud is not None:
                        flickr_token = flickr_oauth.oauth_token
                        logging.info('User Details modified ... updating flickr token %s' % flickr_token)
                        user_token.flickr_token=flickr_token
                        user_token_modified=True
                if user_details is not None and user_details["facebook_access_token"] is not None:
                        user_token.facebook_token=user_details["facebook_access_token"]
                        user_token_modified=True
                        if self.ud.facebook_promo_sent == False:
                                taskqueue.add(url='/service/submit/facebook/promo', params={'user_token': user_token.facebook_token, 'user_details_key': str(self.ud.key())})
                                self.ud.facebook_promo_sent=True
                                ud_modified=True
                if user_token_modified:
                        if user_token.user_details is None and self.ud is not None:
                                logging.info('user details for token not defined: ud = %s' %str(self.ud.key()))
                                user_token.user_details=self.ud
			if user_token.user_details is not None:
                        	logging.info('user_token modified ... updating:for user details %s' % str(user_token.user_details.key()))
                        	user_token.put()
			else:
                        	logging.info('user_token user details not defined ....' )
                if ud_modified:
                        logging.info('user details modified updating ...' )
                        self.ud.put()
                self.google_oauth_token, self.twitter_oauth_token, self.facebook_oauth_token, self.evernote_oauth_token, self.picplz_oauth_token= user_token.google_token, user_token.twitter_token, user_token.facebook_token, user_token.evernote_token, user_token.picplz_token