-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathretweet.py
38 lines (31 loc) · 1.47 KB
/
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
# Retweet bot for Twitter, using Python and Tweepy.
# Search query via hashtag or keyword.
# Author: Tyler L. Jones || CyberVox
# Date: Saturday, May 20th - 2017.
# License: MIT License.
import tweepy
from time import sleep
# Import in your Twitter application keys, tokens, and secrets.
# Make sure your keys.py file lives in the same directory as this .py file.
from keys import *
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Where q='#example', change #example to whatever hashtag or keyword you want to search.
# Where items(5), change 5 to the amount of retweets you want to tweet.
# Make sure you read Twitter's rules on automation - don't spam!
for tweet in tweepy.Cursor(api.search, q='#example').items(5):
try:
print('\nRetweet Bot found tweet by @' + tweet.user.screen_name + '. ' + 'Attempting to retweet.')
tweet.retweet()
print('Retweet published successfully.')
# Where sleep(10), sleep is measured in seconds.
# Change 10 to amount of seconds you want to have in-between retweets.
# Read Twitter's rules on automation. Don't spam!
sleep(10)
# Some basic error handling. Will print out why retweet failed, into your terminal.
except tweepy.TweepError as error:
print('\nError. Retweet not successful. Reason: ')
print(error.reason)
except StopIteration:
break