-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_collection.py
27 lines (24 loc) · 924 Bytes
/
data_collection.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
#this file runs to collect data and store in a file
import tweetstream
import guess_language
def collect(fileName):
stream = tweetstream.SampleStream("varley_jake", "mypassword")
f = open(fileName,'a')
for tweet in stream:
#print tweet.keys()
text = tweet.get('text')
date = tweet.get('created_at')
geo = tweet.get('geo')
language = tweet.get('lang')
location = tweet.get('location')
if (text != None):
lang = guess_language.guessLanguage(text)
if (lang == 'fr'):
print text.encode('utf8') + "\n\n"
print "date: " + str(date)
print "geo: " + str(geo)
print "location: " + str(location)
print "language: " + str(language)
f.write("\n\n" + str(tweet).encode('utf8'))
if __name__ == "__main__":
collect("samples2.txt")