Skip to content

Instantly share code, notes, and snippets.

Created April 29, 2017 16:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# -*- coding: utf-8 -*-
* to install the needed twitter module please run:
* pip install python-twitter
import twitter
from pprint import pprint
def main():
api = twitter.Api(consumer_key="YOUR_KEY_HERE",
search = api.GetSearch("#f57", count=100, result_type="recent")
locations = {}
num = 0
for _search in search:
num += 1
location = _search.user.location.encode('utf-8')
if len(location) > 0:
if locations.get(location) is None:
locations[location] = [_search]
locations[location] += [_search]
print ""
print "locations:"
for loc in locations:
print loc, len(locations[loc])
for _search in locations[loc]:
print "text: {0}".format(_search.text.encode('utf-8'))
print "tweet url:{0}/status/{1}" \
print "========"
print '----'
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment