Skip to content

Instantly share code, notes, and snippets.

@ollybritton
Created June 10, 2017 14:11
Show Gist options
  • Save ollybritton/ce7b89db6f2304b3e4eebe632288f014 to your computer and use it in GitHub Desktop.
Save ollybritton/ce7b89db6f2304b3e4eebe632288f014 to your computer and use it in GitHub Desktop.
import tweepy, json, random, time, sys
from data import *
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
following_list = api.followers_ids("zaksanderson01")
class StdOutListener(tweepy.StreamListener):
def on_data(self, data):
decoded = json.loads(data)
user = decoded["user"]["screen_name"]
user_id = decoded["user"]["id"]
tweet_text = str(decoded["text"].encode("ascii", "ignore"))
tweet_id = decoded["id"]
choice = random.choice(phrases)
choice = "@" + user + " " + choice
try:
api.update_status( choice, tweet_id )
except tweepy.TweepError as e:
print("")
print("Something went really wrong. huh:")
print(e)
print("")
print("")
random_delay = int(round(random.randint(90, 150) * 10) / 10)
print("Waiting " + str(round(random_delay/60)) + " more minutes!")
for i in range(1, random_delay):
print(str(random_delay - i) + " seconds left.")
time.sleep(1)
sys.stdout.write("\033[F") #back to previous line
sys.stdout.write("\033[K") #clear line
print("")
def on_error(self, status):
print(status)
if __name__ == '__main__':
l = StdOutListener()
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
print("")
print("Starting the cycle again!")
print("")
# There are different kinds of streams: public stream, user stream, multi-user streams
# In this example follow #programming tag
# For more details refer to https://dev.twitter.com/docs/streaming-apis
stream = tweepy.Stream(auth, l)
stream.filter( track = ["donald", "trump", "news", "fake news", "president"] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment