Skip to content

Instantly share code, notes, and snippets.

@abehmiel
Created July 18, 2017 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abehmiel/28341e26022345fc2f7d169814afec7f to your computer and use it in GitHub Desktop.
Save abehmiel/28341e26022345fc2f7d169814afec7f to your computer and use it in GitHub Desktop.
Super-simple cursor twitter bot framework
import tweepy
from time import sleep
from creds import *
from random import randint
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
matches = ['Hello world',
'Hello, world',
'Hello, World!']
phrases = ['Someone wrote, "hello world"',
'Yet another "hello world"',
'I see another "hello world"']
for tweet in tweepy.Cursor(api.search, q=matches).items():
try:
# Add \n escape character to print() to organize tweets
print('\nTweet by: @' + tweet.user.screen_name + ': ' + tweet.text)
# Retweet tweets as they are found
# tweet.retweet()
# print('Retweeted the tweet')
# Retweet with comment by embedding status URL
url = 'https://twitter.com/' + tweet.user.screen_name + '/status/' + tweet.id_str
pickPhrase = phrases[randint(0, len(phrases)-1)]
statusMsg = pickPhrase + ' ' + url
# api.update_status(status=statusMsg)
print(statusMsg)
# to avoid rate-limitation
sleep(5)
except tweepy.TweepError as e:
print(e.reason)
except StopIteration:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment