Created
January 16, 2017 15:43
-
-
Save rocapp/be3a922fc92d2d57dc33f91fff18ea8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StdOutListener(StreamListener): | |
""" A listener handles tweets that are received from the stream. | |
This is a basic listener that just prints received tweets to stdout. | |
""" | |
def __init__(self): | |
self.dat = list() | |
self.i = 0 | |
def on_data(self, data): | |
sdat = unicode(data.split('"text":')[1].split(',')[0].replace('"','')) | |
ssdat = [sw for sw in sdat.split(' ') if not any([na for na in ['/', '\\'] if na in sw])] | |
with open('tweets.txt', 'a+') as fw: | |
for ss in ssdat: | |
if ss not in self.dat: | |
print(ss) | |
fw.write(ss+'\n') | |
self.dat.extend(ssdat) | |
self.i += 1 | |
return True | |
def on_error(self, status): | |
print(status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment