-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitterbot1.py
39 lines (32 loc) · 1.11 KB
/
twitterbot1.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
import tweepy
import time
from tokens import *
auth = tweepy.OAuthHandler(apiKey, apiKeySecret)
auth.set_access_token(accessToken, accessTokenSecret)
api = tweepy.API(auth, wait_on_rate_limit=True,
wait_on_rate_limit_notify=True)
user = api.me()
search = '#afrodevs OR #blacktechtwitter OR #Python OR #naijadev OR #naijatech OR #amplifyblackvoices'
nrTweets = 30
for tweet in tweepy.Cursor(api.search, q=(search), lang='en').items(nrTweets):
try:
print('\nTweet by: @' + tweet.user.screen_name)
tweet.retweet()
print('retweeted tweet')
time.sleep(10)
except tweepy.TweepError as e:
print(e.reason)
except StopIteration:
break
for tweet in tweepy.Cursor(api.search, q=(search), lang='en').items(nrTweets):
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')
time.sleep(5)
except tweepy.TweepError as e:
print(e.reason)
except StopIteration:
break