当前位置: 首页>>代码示例>>Python>>正文


Python User.friends_count方法代码示例

本文整理汇总了Python中model.User.friends_count方法的典型用法代码示例。如果您正苦于以下问题:Python User.friends_count方法的具体用法?Python User.friends_count怎么用?Python User.friends_count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.User的用法示例。


在下文中一共展示了User.friends_count方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: friends

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import friends_count [as 别名]
 def friends(self, user_id):
     if not (self.access_token and self.access_token_secret):
         self._authorize()
     page = 1
     while True:
         self.logger.info('On page %s of the friends of user %s' % (page, user_id))
         session = OAuth1Session(
             consumer_key=self.key,
             consumer_secret=self.secret,
             access_token=self.access_token,
             access_token_secret=self.access_token_secret,
         )
         endpoint = 'https://www.goodreads.com/friend/user/%s' % (user_id)
         params = {'format': 'xml', 'key': self.key, 'page': page}
         r = session.get(endpoint, params=params)
         if r.status_code != 200:
             raise GoodReadsError(r.text)
         soup = BeautifulSoup(r.content, 'xml')
         end = int(soup.GoodreadsResponse.friends['end'])
         total = int(soup.GoodreadsResponse.friends['total'])
         users = soup.GoodreadsResponse.friends
         for user_tag in users.find_all('user'):
             user = User(int(user_tag.id.text))
             user.name = user_tag.find('name').text
             user.link = user_tag.link.text
             user.friends_count = int(user_tag.friends_count.text)
             user.reviews_count = int(user_tag.reviews_count.text)
             try:
                 user.created_at = date_parser.parse(user_tag.created_at.text)
             except:
                 pass
             yield user
         if end >= total:
             break
         page += 1
开发者ID:linron84,项目名称:pygoodreads,代码行数:37,代码来源:client.py

示例2: oauth_authorized

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import friends_count [as 别名]
def oauth_authorized(resp):
    """Called after authorization.  After this function finished handling,
    the OAuth information is removed from the session again.  When this
    happened, the tokengetter from above is used to retrieve the oauth
    token and secret.

    Because the remote application could have re-authorized the application
    it is necessary to update the values in the database.

    If the application redirected back after denying, the response passed
    to the function will be `None`.  Otherwise a dictionary with the values
    the application submitted.  Note that Twitter itself does not really
    redirect back unless the user clicks on the application name.
    """
    next_url = request.args.get('next') or url_for('index')
    if resp is None:
        #TODO: show friendly message
        #flash(u'You denied the request to sign in.')
        return redirect(next_url)

    screen_name = resp['screen_name']
    oauth_token = resp['oauth_token']
    oauth_token_secret = resp['oauth_token_secret']
    
    user = User.select_by_screen_name(screen_name)
    if not user:
        app.logger.debug('User not found on database. Using the Twitter API')
        auth = tweepy.OAuthHandler(config.CONSUMER_KEY, config.CONSUMER_SECRET)
        auth.set_access_token(oauth_token, oauth_token_secret)
        api = tweepy.API(auth)
        twitter_user = api.get_user(screen_name=screen_name)
        user = User()
        user.id = twitter_user.id
        user.screen_name = twitter_user.screen_name
        user.blocked = 'N'
        user.name = twitter_user.name
        user.description = twitter_user.description
        user.created_at = twitter_user.created_at
        user.friends_count = twitter_user.friends_count
        user.followers_count = twitter_user.followers_count
        user.statuses_count = twitter_user.statuses_count
        user.profile_image_url = twitter_user.profile_image_url
        user.lang = twitter_user.lang
        user.location = twitter_user.location
        user.oauth_token = oauth_token
        user.oauth_token_secret = oauth_token_secret
        User.add(user)
    else:
        user.oauth_token = oauth_token
        user.oauth_token_secret = oauth_token_secret

    flask.session['screen_name'] = resp['screen_name']
    flask.session['oauth_token'] = resp['oauth_token']
    flask.session['oauth_token_secret'] = resp['oauth_token_secret']
    
    commit()
    
    return flask.redirect(next_url)
开发者ID:panisson,项目名称:whatshot,代码行数:60,代码来源:app.py

示例3: user

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import friends_count [as 别名]
 def user(self, user_id):
     endpoint = 'https://www.goodreads.com/user/show/%s.xml' % (user_id)
     params = {'key': self.key}
     r = requests.get(endpoint, params=params)
     if r.status_code != 200:
         raise GoodReadsError(r.text)
     soup = BeautifulSoup(r.content, 'xml')
     user_tag = soup.user
     user = User(int(user_tag.id.text))
     user.name = user_tag.find('name').text
     user.link = user_tag.link.text
     user.friends_count = int(user_tag.friends_count.text)
     user.reviews_count = int(user_tag.reviews_count.text)
     return user
开发者ID:linron84,项目名称:pygoodreads,代码行数:16,代码来源:client.py


注:本文中的model.User.friends_count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。