From bb94e62a10b4d0b6126503082d89ab3be82e8c84 Mon Sep 17 00:00:00 2001 From: "Tyler L. Jones" Date: Sat, 20 May 2017 12:34:30 -0400 Subject: [PATCH] Added files via upload. (retweet.py & keys.py) --- keys.py | 6 ++++++ retweet.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 keys.py create mode 100644 retweet.py diff --git a/keys.py b/keys.py new file mode 100644 index 0000000..7f85588 --- /dev/null +++ b/keys.py @@ -0,0 +1,6 @@ +# Twitter application consumer keys and access tokens. +# Remember, keep this information private. +consumer_key = 'XXXXXXXXXX' +consumer_secret = 'XXXXXXXXXX' +access_token = 'XXXXXXXXXX' +access_token_secret = 'XXXXXXXXXX' diff --git a/retweet.py b/retweet.py new file mode 100644 index 0000000..ab4645e --- /dev/null +++ b/retweet.py @@ -0,0 +1,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