-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter_RT_bot.py
36 lines (23 loc) · 1.04 KB
/
twitter_RT_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import tweepy
import time
print("Testing The bot")
api_key = 'enter you token here'
api_secret = 'enter you token here'
bearer_token = r"enter you token here"
access_token = 'enter you token here'
access_token_secret = 'enter you token here'
client = tweepy.Client(bearer_token,api_key, api_secret, access_token, access_token_secret)
auth = tweepy.OAuth1UserHandler(api_key, api_secret, access_token, access_token_secret)
api = tweepy.API(auth)
class MyStream(tweepy.StreamingClient):
def on_tweet(self, tweet): #detects the tweet
print(tweet.text)
time.sleep(0.3) # to slow up the coming tweets a bit
try:
client.retweet(tweet.id)
except Exception as error:
print(error)
stream = MyStream(bearer_token=bearer_token)
rule = tweepy.StreamRule("(#Python OR #python OR #programming OR #coding) (-is:retweet -is:reply)") # setting rule on what topics you want to Retweet and not to add replies and retweets. This will only pickup the original tweets
stream.add_rules(rule)
stream.filter()