python bot twitter

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python bot twitter相关的知识,希望对你有一定的参考价值。

# Import Tweepy, sleep, credentials.py
import tweepy
from time import sleep
from credentials import *

# Access and authorize our Twitter credentials from credentials.py
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

for tweet in tweepy.Cursor(api.search, q=('#Polio OR #SPFx -filter:retweets'), lang='en').items(5):
    try:
        # Add \n escape character to print() to organize tweets
        print('\nTweet by: @' + tweet.user.screen_name)

        # Retweet tweets as they are found
        tweet.retweet()
        print('Retweeted the tweet')

    except tweepy.TweepError as e:
        print(e.reason)

    except StopIteration:
        break

for tweet in tweepy.Cursor(api.search, q=('#Arduino OR #GIS OR #Python OR #EndPolio OR #Triathlon-filter:retweets'),lang='en').items(10):
            try:
                # Add \n escape character to print() to organize tweets
                print('\nTweet by: @' + tweet.user.screen_name)

                # Retweet tweets as they are found
                tweet.favorite()
                print('Like the tweet')

                sleep(5)

            except tweepy.TweepError as e:
                print(e.reason)

            except StopIteration:
                break

以上是关于python bot twitter的主要内容,如果未能解决你的问题,请参考以下文章

ruby 马尔科夫Twitter Bot

Node.js Twitter Bot 返回错误:错误的 Twitter 流请求:410

ruby 感谢跟随我使用ruby的twitter bot

Twitter Bot Node.js 和 Twit 包

Twitter“good bot”标签现向所有自动账户持有人公开提供

如何使用 Rails 让我的 Twitter Bot 保持清醒?