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


Python TwitterUser.upsert_from_api_user方法代码示例

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


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

示例1: complete_signin

# 需要导入模块: from smarttypes.model.twitter_user import TwitterUser [as 别名]
# 或者: from smarttypes.model.twitter_user.TwitterUser import upsert_from_api_user [as 别名]
def complete_signin(request_key, verifier, postgres_handle):
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    session = TwitterSession.get_by_request_key(request_key, postgres_handle)
    if session.access_key:
        #this happens if we get multiple same exact responses from twitter
        #perhaps crazy clicking or back / forward browsing 
        credentials = TwitterCredentials.get_by_access_key(session.access_key, postgres_handle)
    else:
        auth.set_request_token(request_key, session.request_secret)
        auth.get_access_token(verifier)
        # may have signed up already
        credentials = TwitterCredentials.get_by_access_key(auth.access_token.key, postgres_handle)
        if not credentials:
            credentials = TwitterCredentials.create(auth.access_token.key, auth.access_token.secret, postgres_handle)
        session.access_key = credentials.access_key
    if not credentials.twitter_user:
        #probably don't have the user in our db yet
        user = TwitterUser.upsert_from_api_user(credentials.api_handle.me(), postgres_handle)
        credentials.twitter_id = user.id
        credentials.save()

    #email
    screen_name = credentials.twitter_user.screen_name
    email_utils.send_email('[email protected]', ['[email protected]'],
                           '%s signed up' % screen_name, 'smarttypes signup!')

    return session.save()
开发者ID:mrcrabby,项目名称:smarttypes,代码行数:29,代码来源:twitter_api_utils.py

示例2: complete_signin

# 需要导入模块: from smarttypes.model.twitter_user import TwitterUser [as 别名]
# 或者: from smarttypes.model.twitter_user.TwitterUser import upsert_from_api_user [as 别名]
def complete_signin(request_key, verifier, postgres_handle):
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    session = TwitterSession.get_by_request_key(request_key, postgres_handle)
    auth.set_request_token(request_key, session.request_secret)
    auth.get_access_token(verifier)
    # may have signed up already
    credentials = TwitterCredentials.get_by_access_key(auth.access_token.key, postgres_handle)
    if not credentials:
        credentials = TwitterCredentials.create(auth.access_token.key, auth.access_token.secret, postgres_handle)
    session.access_key = credentials.access_key
    if not credentials.twitter_user:
        user = TwitterUser.upsert_from_api_user(credentials.api_handle.me(), postgres_handle)
        credentials.twitter_id = user.id
        credentials.save()
    screen_name = credentials.twitter_user.screen_name
    email_utils.send_email('[email protected]', ['[email protected]'],
                           '%s signed up' % screen_name, 'smarttypes signup!')
    return session.save()
开发者ID:galabad,项目名称:smarttypes,代码行数:20,代码来源:twitter_api_utils.py

示例3: str

# 需要导入模块: from smarttypes.model.twitter_user import TwitterUser [as 别名]
# 或者: from smarttypes.model.twitter_user.TwitterUser import upsert_from_api_user [as 别名]
    except TweepError, ex:
        print "%s: api_handle.get_user(%s) got a TweepError %s" % (root_user.screen_name, user_id, ex)
        if 'Sorry, that page does not exist' in str(ex) or 'User has been suspended' in str(ex):
            print 'setting caused_an_error'
            model_user = TwitterUser.get_by_id(user_id, postgres_handle)
            if not model_user:
                properties = {'id': user_id, 'screen_name': user_id}
                model_user = TwitterUser(postgres_handle=postgres_handle, **properties)
                model_user.save()
                postgres_handle.connection.commit()
            model_user.caused_an_error = datetime.now()
            model_user.save()
            postgres_handle.connection.commit()
        return None

    model_user = TwitterUser.upsert_from_api_user(api_user, postgres_handle)
    postgres_handle.connection.commit()
    screen_name = model_user.screen_name

    if api_user.protected:
        print "%s: %s is protected." % (root_user.screen_name, screen_name)
        return model_user

    following_ids = []
    print "%s: loading the people %s follows." % (root_user.screen_name, screen_name)
    try:
        max_pages = 1#5 if is_root_user else 1
        following_id_pages = tweepy.Cursor(api_handle.friends_ids, user_id=user_id).pages(max_pages)
        for following_ids_page in following_id_pages:
            following_ids += [str(x) for x in following_ids_page]
    except TweepError, ex:
开发者ID:mrcrabby,项目名称:smarttypes,代码行数:33,代码来源:get_twitter_friends.py

示例4: len

# 需要导入模块: from smarttypes.model.twitter_user import TwitterUser [as 别名]
# 或者: from smarttypes.model.twitter_user.TwitterUser import upsert_from_api_user [as 别名]
            string.ljust(creds.email if creds.email else '', 30)
        )

if __name__ == "__main__":

    """
    if no args, show all creds
    if args, first arg is creds_username, second is root_username
    """
    if len(sys.argv) == 1:
        list_cred_details()

    elif len(sys.argv) == 2:
        creds_user = TwitterUser.by_screen_name(sys.argv[1], postgres_handle)
        creds = TwitterCredentials.get_by_twitter_id(creds_user.id, postgres_handle)
        creds.root_user_id = None
        creds.save()
        postgres_handle.connection.commit()

    else:
        creds_user = TwitterUser.by_screen_name(sys.argv[1], postgres_handle)
        root_user = TwitterUser.by_screen_name(sys.argv[2], postgres_handle)
        if not root_user:
            api_user = creds_user.credentials.api_handle.get_user(screen_name=sys.argv[2])
            root_user = TwitterUser.upsert_from_api_user(api_user, postgres_handle)
            postgres_handle.connection.commit()
        creds = TwitterCredentials.get_by_twitter_id(creds_user.id, postgres_handle)
        creds.root_user_id = root_user.id
        creds.save()
        postgres_handle.connection.commit()
开发者ID:mrcrabby,项目名称:smarttypes,代码行数:32,代码来源:manage_twitter_credentials.py

示例5: load_user_and_the_people_they_follow

# 需要导入模块: from smarttypes.model.twitter_user import TwitterUser [as 别名]
# 或者: from smarttypes.model.twitter_user.TwitterUser import upsert_from_api_user [as 别名]
def load_user_and_the_people_they_follow(api_handle, screen_name):
    print "Attempting to load %s" % screen_name
    continue_or_exit(api_handle)
    
    try:    
        api_user = api_handle.get_user(screen_name=screen_name)
    except TweepError, ex:
        print "Got a TweepError: %s." % ex  
        if str(ex) == "Not found":
            print "Setting caused_an_error for %s " % screen_name
            model_user = TwitterUser.by_screen_name(screen_name)
            model_user.caused_an_error = datetime.now()
            model_user.save()
            return model_user
    
    model_user = TwitterUser.upsert_from_api_user(api_user)        
    
    if api_user.protected:
        print "\t %s is protected" % screen_name
        return     
    
    if api_user.friends_count > MAX_FOLLOWING_COUNT:
        print "\t %s follows too many people, %s" % (screen_name, api_user.friends_count)
        model_user.save_following_ids([])
        return model_user
    
    print "Loading the people %s follows" % screen_name    
    following_ids = []
    try:
        api_following_list = list(tweepy.Cursor(api_handle.friends, screen_name).items())
    except TweepError, ex:
开发者ID:greeness,项目名称:SmartTypes,代码行数:33,代码来源:get_twitter_friends.py


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