Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Greco committed Feb 4, 2017
1 parent 6fe9f4d commit 016ef7b
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
51 changes: 51 additions & 0 deletions excludeDict.py
@@ -0,0 +1,51 @@
i = [
'rt:',
'https',
'@',
'trump',
'president',
'amp'
]

d = [
'trump',
"say",
"new",
"want",
"trump's",
'donald',
'why',
'i',
'a',
'the',
'how',
'when',
'where',
'what',
'who',
'to',
'of',
'so',
'them',
'you',
'him',
'but',
'his',
'will',
'now',
'via',
'amp'
]

def excludeWord(s):
if isinstance(s, unicode):
return True
if len(s) <= 2:
return True
for word in i:
if word in s:
return True
for word in d:
if word == s:
return True
return False
40 changes: 40 additions & 0 deletions main.py
@@ -0,0 +1,40 @@
import json, sys, os, tweepy, string, excludeDict
from tweepy import OAuthHandler, Stream
from tweepy.streaming import StreamListener

consumer_key = ''
consumer_secret = ''

access_token = ''
access_secret = ''

# TWITTER API BUILDING
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
printable = set(string.printable)



class MyListener(StreamListener):


def on_data(self, data):
d = json.loads(data)
if 'text' in d:
txt = d['text']
txt = filter(lambda x: x in printable, txt)
with open('words.txt', 'a') as fi:
for word in txt.lower().split():
if not excludeDict.excludeWord(str(word)):
fi.write(word + '\n')
fi.close()

def on_error(self, status):
print(status)
return True

# --------------------------------------

twitter_stream = Stream(auth, MyListener())
twitter_stream.filter(track=['Trump', "Donald", "Donald Trump"])
35 changes: 35 additions & 0 deletions push.py
@@ -0,0 +1,35 @@
import sys, os, tweepy, time
from tweepy import OAuthHandler
from wordcloud import WordCloud
import numpy as np
from PIL import Image
from os import path

consumer_key = ''
consumer_secret = ''
access_token = ''
access_secret = ''

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)

d = path.dirname(__file__)



mask = np.array(Image.open(path.join(d, "trump_mask.png")))




while(True):
time.sleep(21600) # Change to frequency you want
text = open("words.txt").read()
wc = WordCloud(max_words=250, mask=mask, margin=10,
random_state=1, width=2048, height=2048).generate(text)
wc.to_file("trumpCloud.png")
with open('words.txt', 'w') as fi:
fi.write('')
api.update_with_media('trumpCloud.png', '')
print 'Tweet published'

0 comments on commit 016ef7b

Please sign in to comment.