-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmagabot-pi.py
64 lines (48 loc) · 2.54 KB
/
magabot-pi.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
#Magabot will look for tweets with the Make America Great Again hashtag (#maga) + [bitch,cunt,slut,whore]
#Magabot will then read them aloud to you.
#Run it in the background while you work for a great day!
#And remember, the stream API represents just a small fraction
#of the actual tweets that go out every minute.
import json
import os
import re
# Import the necessary methods from "twitter" library
from twitter import Twitter, OAuth, TwitterHTTPError, TwitterStream
# Variables that contains the user credentials to access Twitter API
# Go to dev.twitter.com, using your twitter account, you will need to set up
# an "app" in order to get your API keys and tokens
CONSUMER_KEY = 'yourkeygoeshere' #or, better yet, somewhere else
CONSUMER_SECRET = 'yoursecretconsumerkeygoeshere' #or, better yet, somewhere else
ACCESS_TOKEN = 'youraccesstokengoeshere' #or, better yet, somewhere else
ACCESS_SECRET = 'yoursecretaccesstokengoeshere' #or, better yet, somewhere else
oauth = OAuth(ACCESS_TOKEN, ACCESS_SECRET, CONSUMER_KEY, CONSUMER_SECRET)
# Initiate the connection to Twitter Streaming API
twitter_stream = TwitterStream(auth=oauth)
#you can change the search terms here, but why would you? FUN!!!
iterator = twitter_stream.statuses.filter(track="#maga slut,#maga bitch,#maga whore, #maga cunt", language="en")
# Here we set it to stop after getting 100 tweets.
# You don't have to set it to stop
tweet_count = 100
for tweet in iterator:
tweet_count -= 1
# Print each tweet in the stream to the screen
# to convert it back to the JSON format to print/score
#print json.dumps(tweet)
if 'text' in tweet: # only messages contains 'text' field is a tweet
#print 'http://twitter.com/statuses/%i' %tweet['id']
print tweet['id'] # This is the tweet's id
print tweet['created_at'] # when the tweet posted
print tweet['user']['name'] # name of the user
print tweet['user']['screen_name'] # name of the user account
print tweet['text'] # content of the tweet
#convert tweet text to unicode so flite can read it
tweettext=unicode(tweet['text']).encode('utf-8')
#take out the URLs using regex because they're weird
tweettext=re.sub(r"http\S+","", tweettext)
#read the tweets using flite...p.s. you have to install flite
#sudo apt-get install flite
os.system("flite -voice slt -t 'Incoming:"+tweettext+"ALL DONE'")
#time.sleep(5)
if tweet_count <= 0:
break