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


Python tweepy.Cursor方法代码示例

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


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

示例1: _add

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def _add(self, ctx, account, channel:discord.Channel=None):
        """Adds a twitter account to the specified channel"""
        api = await self.authenticate()
        try:
            for status in tw.Cursor(api.user_timeline, id=account).items(1):
                user_id = str(status.user.id)
                screen_name = status.user.screen_name
                last_id = status.id
        
        except tw.TweepError as e:
            print("Whoops! Something went wrong here. \
                    The error code is " + str(e) + account)
            await self.bot.say("That account does not exist! Try again")
            return
        if channel is None:
            channel = ctx.message.channel
        added = await self.add_account(channel, user_id, screen_name)
        if added:
            await self.bot.say("{0} Added to {1}!".format(account, channel.mention))
        else:
            await self.bot.say("{} is already posting or could not be added to {}".format(account, channel.mention)) 
开发者ID:TrustyJAID,项目名称:Trusty-cogs-archive,代码行数:23,代码来源:tweets.py

示例2: _del

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def _del(self, ctx, account, channel:discord.Channel=None):
        """Removes a twitter account to the specified channel"""
        account = account.lower()
        api = await self.authenticate()
        if channel is None:
            channel = ctx.message.channel
        try:
            for status in tw.Cursor(api.user_timeline, id=account).items(1):
                user_id = str(status.user.id)      
        except tw.TweepError as e:
            print("Whoops! Something went wrong here. \
                    The error code is " + str(e) + account)
            await self.bot.say("That account does not exist! Try again")
            return
        removed = await self.del_account(channel, user_id)
        if removed:
            await self.bot.say("{} has been removed from {}".format(account, channel.mention))
        else:
            await self.bot.say("{0} doesn't seem to be posting in {1}!"
                               .format(account, channel.mention)) 
开发者ID:TrustyJAID,项目名称:Trusty-cogs-archive,代码行数:22,代码来源:tweets.py

示例3: get_friends

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def get_friends(api, screen_name, max_connections=0):
    friends = []
    max_connections_reached = False
    try:
        for friend_ids in tweepy.Cursor(
                api.friends_ids, screen_name=screen_name).pages():
            if max_connections and (
                    len(friends) + len(friend_ids)) > max_connections:
                logger.info(
                    'Max connections reached... trimming final request')
                friend_ids = friend_ids[:max_connections - len(friends)]
                max_connections_reached = True
            friends.extend(lookup_users(api, friend_ids))
            if max_connections_reached:
                break
    except Exception as e:
        logger.error('Error fetching friends: {}'.format(e))
    return friends 
开发者ID:duo-labs,项目名称:twitterbots,代码行数:20,代码来源:crawl_network.py

示例4: get_followers

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def get_followers(api, screen_name, max_connections=0):
    followers = []
    max_connections_reached = False
    try:
        for follower_ids in tweepy.Cursor(
                api.followers_ids, screen_name=screen_name).pages():
            if max_connections and (
                    len(followers) + len(follower_ids)) > max_connections:
                logger.info(
                    'Max connections reached... trimming final request')
                follower_ids = follower_ids[:max_connections - len(followers)]
                max_connections_reached = True
            followers.extend(lookup_users(api, follower_ids))
            if max_connections_reached:
                break
    except Exception as e:
        logger.error('Error fetching friends: {}'.format(e))
    return followers 
开发者ID:duo-labs,项目名称:twitterbots,代码行数:20,代码来源:crawl_network.py

示例5: twitSearch

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def twitSearch(t_api):
    t_query = raw_input('Enter search: ')
    t_res = tweepy.Cursor(t_api.search, q=t_query, count=10,
                          result='recent',
                          include_entities=True).items()
    while True:
        try:
            tweet = t_res.next()
            print tweet.user.screen_name.encode('utf-8'), ':', \
                tweet.created_at, ':', tweet.text.encode('utf-8')
            print   # print an extra line...just for readability
            sleep(5)  # sleep so it is human readable
        except tweepy.TweepError:

      # if tweepy encounters an error, sleep for fifteen minutes..this will
      # help against API bans.

            sleep(60 * 15)
        except KeyboardInterrupt:
            return 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:22,代码来源:oscrtwitter.py

示例6: dm_batch

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def dm_batch(t_api):
    print "You are about to Delete all RECEIEVED DMs from the account @%s." % t_api.verify_credentials().screen_name
    print "Does this sound ok? There is no undo! Type yes to carry out this action."
    do_delete = raw_input("> ")
    if do_delete.lower() == 'yes':
        direct_messages = tweepy.Cursor(t_api.direct_messages).items()
        for direct_message in itertools.islice(direct_messages,0,None):
        #for message in tweepy.Cursor(t_api.direct_messages).items():
            try:
                #t_api.destroy_direct_message(message.id)
                t_api.destroy_direct_message(direct_message.id)
                print "Deleted:", direct_message.id
            except:
                print "Failed to delete:", direct_message.id
            sleep(5)
    return 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:18,代码来源:oscrtwitter.py

示例7: dm_sent

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def dm_sent(t_api):
    print "You are about to Delete all SENT DMs from the account @%s." % t_api.verify_credentials().screen_name
    print "Does this sound ok? There is no undo! Type yes to carry out this action."
    do_delete = raw_input("> ")
    if do_delete.lower() == 'yes':
        sent_direct_messages = tweepy.Cursor(t_api.sent_direct_messages).items()
        for direct_message in itertools.islice(sent_direct_messages,0,None):
        #for message in tweepy.Cursor(t_api.direct_messages).items():
            try:
                #t_api.destroy_direct_message(message.id)
                t_api.destroy_direct_message(direct_message.id)
                print "Deleted:", direct_message.id
            except:
                print "Failed to delete:", direct_message.id
            sleep(5)
    return 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:18,代码来源:oscrtwitter.py

示例8: ensure_users_edges_in_db

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def ensure_users_edges_in_db(user, edges_collection, twitter_api):
    "Looks up a user's friends_ids and followers_ids on the twitter api, and stores the edges in db."

    logging.info(".. Fetching followers_ids for user {0}.".format(user['id']))
    logging.info(".... user has {0} followers.".format(user['followers_count']))
    cursor = Cursor(twitter_api.followers_ids, id=user['id'])
    edges = [{ 'from' : follower_id,
               'to'   : user['id']}
            for follower_id in cursor.items()]
    store_edges(edges_collection, edges)
    followers_ids = [edge['from'] for edge in edges]

    logging.info(".. Fetching friends_ids for user {0}.".format(user['id']))
    logging.info(".... user has {0} friends.".format(user['friends_count']))
    cursor = Cursor(twitter_api.friends_ids, id=user['id'])
    edges = [{ 'to'   : friend_id,
               'from' : user['id']}
            for friend_id in cursor.items()]
    store_edges(edges_collection, edges)
    friends_ids = [edge['to'] for edge in edges]

    return friends_ids, followers_ids 
开发者ID:SMAPPNYU,项目名称:smappPy,代码行数:24,代码来源:build_follower_network.py

示例9: user_tweets

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def user_tweets(api, user_id=None, screen_name=None, limit=None, **kwargs):
    """
    Queries Twitter REST API for user's tweets. Returns as many as possible, or
    up to given limit.
    Takes an authenticated API object (API or APIPool), one of user_id or screen_name 
    (not both), and an optional limit for number of tweets returned.
    Returns a cursor (iterator) over Tweepy status objects.

    Also takes variable collection of keyword argument to pass on to
    Tweepy/APIPool query methods, to support full API call parameterization.
    """
    if not (user_id or screen_name):
        raise Exception("Must provide one of user_id or screen_name")
    if user_id:
        cursor = Cursor(api.user_timeline, user_id=user_id, count=200,
            **kwargs)
    elif screen_name:
        cursor = Cursor(api.user_timeline, screen_name=screen_name,
            count=200, **kwargs)
    if limit:
        return cursor.items(_check_limit(limit))
    return cursor.items() 
开发者ID:SMAPPNYU,项目名称:smappPy,代码行数:24,代码来源:get_tweets.py

示例10: get_friends_ids

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def get_friends_ids(api, user_id):
    """
    Given a Tweepy/smappPy TweepyPool api, query twitter's rest API for friends of
    given user_id. Returns IDs only (much faster / more per request).
    Parameters:
        api     - fully authenticated Tweepy api or smappPy TweepyPool api
        user_id - twitter user id
    Returns tuple: return code, list of IDs or None (if API call fails)
    """
    cursor = Cursor(api.friends_ids, user_id=user_id)
    user_list, ret_code = call_with_error_handling(list, cursor.items())
   
    if ret_code != 0:
        logger.warning("User {0}: Friends request failed".format(user_id))
    
    # Return user list from API or None (call_with_error_handling returns None if
    # call fail)
    return ret_code, user_list 
开发者ID:SMAPPNYU,项目名称:smappPy,代码行数:20,代码来源:build_friends_followers.py

示例11: get_followers_ids

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def get_followers_ids(api, user_id):
    """
    Given a Tweepy/smappPy TweepyPool api, query twitter's rest API for followers of
    given user_id. Returns IDs only (much faster / more per request).
    Parameters:
        api     - fully authenticated Tweepy api or smappPy TweepyPool api
        user_id - twitter user id
    Returns tuple: return code, list of IDs or None (if API call fails)
    """
    cursor = Cursor(api.followers_ids, user_id=user_id)
    user_list, ret_code = call_with_error_handling(list, cursor.items())

    if ret_code != 0:
        logger.warning("User {0}: Followers request failed".format(user_id))
    
    # Return user list from API or None (call_with_error_handling returns None if
    # call fail)
    return ret_code, user_list 
开发者ID:SMAPPNYU,项目名称:smappPy,代码行数:20,代码来源:build_friends_followers.py

示例12: get_medias

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def get_medias(auth, user_id, include_retweets, image_size, since, since_id, until, until_id, likes):
    """Get all medias for a given Twitter user."""
    auth = tweepy.OAuthHandler(auth['consumer_token'], auth['consumer_secret'])
    api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)

    results = {
        'tweets': 0,
        'retweets': 0,
        'media': []
    }
    capi = api.favorites if likes else api.user_timeline
    for tweet in tweepy.Cursor(capi, id=user_id, include_rts=include_retweets, include_entities=True, tweet_mode='extended', since_id=since_id, max_id=until_id).items():
        if since is not None and tweet.created_at < since:
            break
        if until is not None and tweet.created_at > until:
            continue
        parse_tweet(tweet, include_retweets, image_size, results)

    print('Medias for user {0}'.format(user_id))
    print('- Tweets: {0}'.format(results['tweets']))
    print('- Retweets: {0}'.format(results['retweets']))
    print('- Parsed: {0}'.format(len(results['media'])))

    return results 
开发者ID:Spark-NF,项目名称:twitter_media_downloader,代码行数:26,代码来源:parser.py

示例13: get_friends

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def get_friends(screen_name):
    """
    https://dev.twitter.com/rest/reference/get/friends/list

    Requests / 15-min window (app auth): 30
    """
    api = get_tweepy_api()
    friends = []
    is_first = True
    for page in tweepy.Cursor(api.friends, screen_name=screen_name, count=200).pages():
        if not is_first:
            time.sleep(30)
        else:
            is_first = False
        friends.extend(page)
    return friends
#    api = get_twitter_api()
#    friends = api.GetFriends(screen_name=screen_name, count=200)
#    return friends 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:21,代码来源:utils.py

示例14: get_friends_ids

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def get_friends_ids(screen_name):
    api = get_tweepy_api()
    ids = []
    is_first = True
    try:
        for page in tweepy.Cursor(api.friends_ids, screen_name=screen_name, count=5000).pages():
            if not is_first:
                time.sleep(60)
            else:
                is_first = False
            ids.extend(page)
    except tweepy.RateLimitError:
        extra_data = {
            'screen_name' : screen_name,
        }
        rollbar.report_exc_info(extra_data=extra_data)
    return ids 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:19,代码来源:utils.py

示例15: get_followers_ids

# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import Cursor [as 别名]
def get_followers_ids(screen_name):
    """
    https://dev.twitter.com/rest/reference/get/followers/ids

    Requests / 15-min window (app auth): 15
    """
    api = get_tweepy_api()
    ids = []
    is_first = True
    try:
        for page in tweepy.Cursor(api.followers_ids, screen_name=screen_name, count=5000).pages():
            if not is_first:
                time.sleep(60)
            else:
                is_first = False
            ids.extend(page)
    except tweepy.RateLimitError:
        extra_data = {
            'screen_name' : screen_name,
        }
        rollbar.report_exc_info(extra_data=extra_data)
    return ids 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:24,代码来源:utils.py


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