简体   繁体   中英

How can I extract tweets from Twitter tagged with latitude and longitude in text file

I want to extract tweets with latitude and longitude from Twitter in text file, using python

For example, I want to have the following in the extracted text file:

[50.4146912, -119.2066755]  6   2011-08-28 19:24:29 @NaomiAKlein @TheRealRoseanne "BreakingNews: President Obama to deliver live statement on Hurricane Irene from Rose Garden - NBC News"
[38.896544300000002, -76.994223250000005]   6   2011-08-28 19:26:31 RT @ProducerMatthew: President Obama to deliver statement at 2pm PT / 5pm ET on Hurricane #Irene from the Rose Garden.
[33.787082099999999, -118.1678924]  6   2011-08-28 19:38:06 Ps. As the joke in itself is what ones know for ones selves as ones do to you yourselves to Obama self, ones government to the police
[43.108731089999999, -89.335464060000007]   6   2011-08-28 19:46:44 “@crewislife: US Federal debt increases by U.S Presidents: Reagan 186% Bush I 54% Clinton 41% Bush II 72% Obama 23% Source: CBO #wiunion
[43.108731089999999, -89.335464060000007]   6   2011-08-28 19:47:40 RT @crewislife: US Federal debt increases by U.S Presidents: Reagan 186% Bush I 54% Clinton 41% Bush II 72% Obama 23% Source: CBO #wiunion

Here's a link to the docs for the Twitter REST API .

And here are the basics to start pulling information down from Twitter:

import urllib2, json, pprint

u = urllib2.urlopen('http://search.twitter.com/search.json?q=obama&rpp=25')
resultdict = json.load(u)

pprint.pprint(resultdict)
for tweet in resultdict['results']:
    print tweet['text']

Note, the long/lat isn't included explicitly. Twitter converts the locations into "placecodes" which you will then need to reverse: https://dev.twitter.com/terms/geo-developer-guidelines

The rest is (as they say) left as an exercise for the reader :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM