Skip to content

Instantly share code, notes, and snippets.

@oldkingcone
Created April 15, 2018 09:21
Show Gist options
  • Save oldkingcone/17142558512879d9712ca843a102a518 to your computer and use it in GitHub Desktop.
Save oldkingcone/17142558512879d9712ca843a102a518 to your computer and use it in GitHub Desktop.
import tweepy
from time import sleep
# creds.py is a custom file that holds all of your consumer keys and API keys. you will need to make it.
from creds import *
import os
from datetime import datetime as dt
import random
auth = tweepy.OAuthHandler(consumer_key=consumer_key, consumer_secret=consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
cont = 0
yes = 'true'
os.system('clear')
# selection options, could 1 line the if statements, but wheres the fun in that.
python = '#python'
bash = '#bash'
scripting = '#scripting'
prog = '#programming'
sec = '#infosec'
# main loop entry, this will loop forever.
while yes == 'true':
if cont == 0:
# choice selection, assigned 1 through 5, choosing topics accordingly.
choice = random.randint(1, 5)
q = ''
if choice == 1:
q = python
print("\nChosing %s for search criteria." % str(q))
for tweet in tweepy.Cursor(api.search, q=q, locale='en').items(10):
try:
sleep_time = random.randint(10, 550)
date_1 = dt.now()
print('\nTweet by: @' + tweet.user.screen_name)
try:
tweet.retweet()
print("Retweeted the Found Tweet")
print("Time: %s" % str(date_1))
except tweepy.TweepError:
pass
if not tweet.user.following:
tweet.user.follow()
print("Followed user!")
try:
print("Favorited the found tweet!")
tweet.favorite()
except:
pass
print("Sleep for: %i seconds" % sleep_time)
sleep(sleep_time)
cont = 0
# continue
except (tweepy.TweepError) as e:
sleep_time = random.randint(10, 50)
print("Something happened: %s" % str(e))
sleep(sleep_time)
cont = 0
continue
except StopIteration:
break
if choice == 2:
q = bash
print("\nChosing %s for search criteria." % str(q))
for tweet in tweepy.Cursor(api.search, q=q, locale = 'en').items(10):
try:
sleep_time = random.randint(10, 550)
date_1 = dt.now()
print('\nTweet by: @' + tweet.user.screen_name)
try:
tweet.retweet()
print("Retweeted the Found Tweet")
print("Time: %s" % str(date_1))
except tweepy.TweepError:
pass
if not tweet.user.following:
tweet.user.follow()
print("Followed user!")
try:
print("Favorited the found tweet!")
tweet.favorite()
except tweepy.TweepError:
pass
print("Sleep for: %i seconds" % sleep_time)
sleep(sleep_time)
cont = 0
# continue
except (tweepy.TweepError) as e:
sleep_time = random.randint(10, 50)
print("Something happened: %s" % str(e))
sleep(sleep_time)
cont = 0
continue
except StopIteration:
break
if choice == 3:
q = scripting
print("\nChosing %s for search criteria." % str(q))
for tweet in tweepy.Cursor(api.search, q=q, locale='en').items(10):
try:
sleep_time = random.randint(10, 550)
date_1 = dt.now()
print('\nTweet by: @' + tweet.user.screen_name)
try:
tweet.retweet()
print("Retweeted the Found Tweet")
print("Time: %s" % str(date_1))
except tweepy.TweepError:
pass
if not tweet.user.following:
tweet.user.follow()
print("Followed user!")
try:
print("Favorited the found tweet!")
tweet.favorite()
except tweepy.TweepError:
pass
print("Sleep for: %i seconds" % sleep_time)
sleep(sleep_time)
cont = 0
# continue
except (tweepy.TweepError) as e:
sleep_time = random.randint(10, 50)
print("Something Happened: %s" % str(e))
sleep(sleep_time)
cont = 0
continue
except StopIteration:
break
if choice == 4:
q = prog
print("\nChosing %s for search criteria." % str(q))
for tweet in tweepy.Cursor(api.search, q=q, locale='en').items(10):
try:
sleep_time = random.randint(10, 550)
date_1 = dt.now()
print('\nTweet by: @' + tweet.user.screen_name)
try:
tweet.retweet()
print("Retweeted the Found Tweet")
print("Time: %s" % str(date_1))
except tweepy.TweepError:
pass
if not tweet.user.following:
tweet.user.follow()
print("Followed user!")
try:
print("Favorited the found tweet!")
tweet.favorite()
except tweepy.TweepError:
pass
print("Sleep for: %i seconds" % sleep_time)
sleep(sleep_time)
cont = 0
# continue
except (tweepy.TweepError) as e:
sleep_time = random.randint(10, 50)
print("Something happened: %s" % str(e))
sleep(sleep_time)
cont = 0
continue
except StopIteration:
break
if choice == 5:
q = sec
print("\nChosing %s for search criteria." % str(q))
for tweet in tweepy.Cursor(api.search, q=q, locale='en').items(10):
try:
sleep_time = random.randint(10, 550)
date_1 = dt.now()
print('\nTweet by: @' + tweet.user.screen_name)
try:
tweet.retweet()
print("Retweeted the Found Tweet")
print("Time: %s" % str(date_1))
except tweepy.TweepError:
pass
if not tweet.user.following:
tweet.user.follow()
print("Followed user!")
try:
print("Favorited the found tweet!")
tweet.favorite()
except:
pass
print("Sleep for: %i seconds" % sleep_time)
sleep(sleep_time)
cont = 0
# continue
except (tweepy.TweepError) as e:
sleep_time = random.randint(10, 50)
print("Something Happened: %s" % str(e))
sleep(sleep_time)
cont = 0
continue
except StopIteration:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment