-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbot.py
51 lines (38 loc) · 1.43 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import tweepy
from time import sleep
# Import in your Twitter application keys, tokens, and secrets.
# Make sure your credentials.py file lives in the same directory as this .py file.
from credentials import *
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Twitter bot setting for liking Tweets
LIKE = True
# Twitter bot setting for following user who tweeted
FOLLOW = False
print("Twitter bot which retweets, like tweets and follow users")
print("Bot Settings")
print("Like Tweets :", LIKE)
print("Follow users :", FOLLOW)
# Change the hashtags by your choice
for tweet in tweepy.Cursor(api.search, q = ('#nifty50 OR #sensex OR #stocks -filter:retweets'),lang='en').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')
# Twitter bot sleep time settings in seconds. Use large delays so that you account will not banned
sleep(300) # 300 seconds = 5 minutes
except tweepy.TweepError as e:
print(e.reason)
except StopIteration:
break