Greetings fellow enthusiasts! I am working on a project and I am utilizing python to interact with the twitter api.
Goal: Extract the location, text of tweet, created at, and user id from the raw data you see returned in the code from the "pprint.pprint(datares)" into a specified format in csv file.
Problem: How can I get the info I am returning into a csv file so that every row in the file would display as follows:
Row: tweet text, it's location, created at, user id
The following is my code and shows what I am able to return so far.
import urllib2, json, pprint, codecs, unicodedata
u = urllib2.urlopen('http://search.twitter.com/search.json?geocode=29.762778,-95.383056,25.0mi&page=1&rpp=20')
datares = json.load(u)
##raw data returned
pprint.pprint(datares)
##open csv file
with codecs.open('Geotweets.csv',mode='w', encoding='utf-8',errors='replace') as cache:
##need to save tweets,date,area,id to file
for tweet in datares['results']:
print tweet['text']
archive=tweet['text']
unicodedata.normalize('NFKD', archive).encode('ascii','ignore')
cache.write(archive)
for date in datares['results']:
print date['created_at']
for area in datares['results']:
print area['location']
for id in datares['results']:
print id['from_user']