-
Notifications
You must be signed in to change notification settings - Fork 40
/
twitterbot_retweet.py
40 lines (31 loc) · 1.04 KB
/
twitterbot_retweet.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
37
38
39
40
import tweepy
from time import sleep
from credentials import *
from config import QUERY, FOLLOW, LIKE, SLEEP_TIME
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
print("Twitter bot which retweets,like tweets and follow users")
print("Bot Settings")
print("Like Tweets :", LIKE)
print("Follow users :", FOLLOW)
for tweet in tweepy.Cursor(api.search, q=QUERY).items():
try:
print('\nTweet by: @' + tweet.user.screen_name)
tweet.retweet()
print('Retweeted the tweet')
# Favorite the tweet
if LIKE:
tweet.favorite()
print('Favorited the tweet')
# Follow the user who tweeted
#check that bot is not already following the user
if FOLLOW:
if not tweet.user.following:
tweet.user.follow()
print('Followed the user')
sleep(SLEEP_TIME)
except tweepy.TweepError as e:
print(e.reason)
except StopIteration:
break