Beispiel #1
0
 def authorize(self, user = None, login=True):
     if self.user is None:
         if user is None:
             raise TypeError
         self.user = user
     """Guarda el token de autorizacion"""
     if self.user is not None:#el usuario ya esta conectado, pero pide permisos
         if OAUTH_Access.get_token(self.token.key) is None: 
             OAUTH_Access.remove_token(self.user, 'twitter')
             access = OAUTH_Access.add_token(
                                             token_key=self.token.key,
                                             token_secret=self.token.secret,
                                             provider='twitter',
                                             user=self.user,
                                             )
         if login:
             twitterInfo = self.get_user_info()
             if self.user.twitter_user is None:
                 TwitterUser.register(user=self.user,
                                  uid=twitterInfo['id'], 
                                  username = twitterInfo['screen_name'],
                                  realname = twitterInfo['name'],
                                  picurl = twitterInfo['profile_image_url'],
                                  )
             else:
                 self.user.twitter_user.update(
                                          username = twitterInfo['screen_name'],
                                          realname = twitterInfo['name'],
                                          picurl = twitterInfo['profile_image_url']
                                          )
         return True
     return False
Beispiel #2
0
 def handle_results(self):
     try:
         result = self.rpc.get_result()
         if int(result.status_code) != 200:
             return {}
         friends_result = simplejson.loads(result.content)
         if len(friends_result) == 0:
             return {}
         friends_key = ['tu%s' % f for f in friends_result]
         users_to_follow = TwitterUser.get_by_key_name(friends_key)
         users_to_follow = filter(None, users_to_follow)
         for user_to_follow in users_to_follow:
             if user_to_follow.user is not None and user_to_follow.user.username is not None and \
                 not self.user.is_following(user_to_follow.user):
                 try:
                     info = TwitterClient(user=user_to_follow.user)
                     info = info.get_user_info()
                     self.friends[user_to_follow.user.id] = { 
                                                'username': user_to_follow.user.username, 
                                                'twittername': info['screen_name'],
                                                'id': user_to_follow.user.id,
                                                }
                 except Exception, e:
                     import logging
                     logging.exception('No se encontro un usuario de twitter buscado por: %s - %s' % (user_to_follow.user.id, e.message))
     except Exception, e:
         import logging
         logging.exception('Handling Exception getting twitter friends: %s - %s' % (self.user.id, e.message))