break if re.findall(r'\b(' + abbrev + r')\b', location, re.IGNORECASE): states_freqs[abbrev] += 1 break return states_freqs Q = ' '.join(sys.argv[1:]) # Don't forget to pass in keyword parameters if you don't have # a token file stored to disk t = oauth_login() _, screen_name_to_location, _ = analyze_users_in_search_results(t, q=Q, max_batches=5, count=100) locations = screen_name_to_location.values() # Resolve state abbreviations to the number of times these states appear states_freqs = get_state_frequencies(locations) # Munge the data to the format expected by Protovis for Dorling Cartogram json_data = {} for state, freq in states_freqs.items(): json_data[state] = {'value': freq} # Copy over some scripts for Protovis... # Our html template references some Protovis scripts, which we can # simply copy into out/
Q = ' '.join(sys.argv[2:]) MAX_HTTP_ERRORS = 100 g = geopy.geocoders.Google(GEOCODING_API_KEY) # Don't forget to pass in keyword parameters if you don't have # a token file stored to disk t = oauth_login() # This function returns a few useful maps. Let's use the # screen_name => location map and geocode the locations _, screen_name_to_location, _ = analyze_users_in_search_results( t, Q, max_pages=1) locations = screen_name_to_location.values() location2coords, location2description = geocode_locations(g, locations) # Doing something interesting like building up some KML to visualize in Google Earth/Maps # just involves some simple string munging... kml = build_kml( "Geocoded user profiles for Twitter search results for " + Q, location2coords) if not os.path.isdir('out'): os.mkdir('out') f = open(os.path.join(os.getcwd(), 'out', Q + ".kml"), 'w') f.write(kml)
break if re.findall(r'\b(' + abbrev + r')\b', location, re.IGNORECASE): states_freqs[abbrev] += 1 break return states_freqs Q = ' '.join(sys.argv[1:]) # Don't forget to pass in keyword parameters if you don't have # a token file stored to disk t = oauth_login() _, screen_name_to_location, _ = analyze_users_in_search_results(t, Q) locations = screen_name_to_location.values() # Resolve state abbreviations to the number of times these states appear states_freqs = get_state_frequencies(locations) # Munge the data to the format expected by Protovis for Dorling Cartogram json_data = {} for state, freq in states_freqs.items(): json_data[state] = {'value': freq} # Copy over some scripts for Protovis... # Our html template references some Protovis scripts, which we can # simply copy into out/