forked from alexstorer/twittersauce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweetanalysis.py
33 lines (25 loc) · 717 Bytes
/
tweetanalysis.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
import twitter
import json
import pickle
import time
import random
import sys
import csv
twitter_stream = twitter.TwitterStream(auth=twitter.UserPassAuth('iqssrtc', '********'))
res = twitter_stream.statuses.filter(track='obama')
reslist = []
tweetfields = set()
for r in res:
if len(reslist)<5000:
print len(reslist)
reslist.append(r)
tweetfields = tweetfields.union(r.keys())
else:
break
fname = '/users/astorer/Work/presentations/twitter/example_tweets.csv'
f = open(fname,'w')
dw = csv.DictWriter(f,fieldnames=list(tweetfields))
dw.writeheader()
for r in reslist:
dw.writerow({k:v.encode('utf8') if isinstance(v,unicode) else v for k,v in r.items()})
f.close()