Skip to content
Browse files

Another batch of minor fixes so that query args to scripts can be mul…

…titerm. Style fixes to make scripts consistent.
  • Loading branch information...
1 parent dd464e6 commit ea76254b39ff84430b2d902f39f1832e5d047d84 @ptwobrussell committed Jan 28, 2011
View
2 recipe__create_rt_graph.py
@@ -29,7 +29,7 @@ def create_rt_graph(tweets):
# Your query
- Q = sys.argv[1]
+ Q = ' '.join(sys.argv[1])
# How many pages of data to grab for the search results
View
41 recipe__geocode_profile_locations.py
@@ -3,13 +3,13 @@
import sys
from urllib2 import HTTPError
import geopy
-from recipe__analyze_users_in_search_results import analyzeUsersInSearchResults
+from recipe__oauth_login import oauth_login
+from recipe__analyze_users_in_search_results import analyze_users_in_search_results
-def geocodeLocations(geocoder, locations):
+def geocode_locations(geocoder, locations):
# Some basic replacement transforms may be necessary for geocoding services to function properly
- # Here are a few examples that seem to cause problems for Yahoo. You'll probably need
- # to add your own as you encounter rough edges in the data or with the geocoding
+ # You may probably need to add your own as you encounter rough edges in the data or with the geocoding
# service you settle on. For example, ...
replacement_transforms = [('San Francisco Bay', 'San Francisco')]
@@ -55,15 +55,15 @@ def geocodeLocations(geocoder, locations):
break
- for result in results:
+ for result in results:
- # Each result is of the form ("Description", (X,Y))
- # Unless you have a some special logic for picking the best of many possible
- # results, choose the first one returned in results and move along
+ # Each result is of the form ("Description", (X,Y))
+ # Unless you have a some special logic for picking the best of many possible
+ # results, choose the first one returned in results and move along
- location_to_coords[location] = result[1]
- location_to_description[location] = result[0]
- break
+ location_to_coords[location] = result[1]
+ location_to_description[location] = result[0]
+ break
# Use location_to_coords and other information of interest to populate a visualization.
# Depending on your particular needs, it is highly likely that you'll want to further
@@ -75,21 +75,26 @@ def geocodeLocations(geocoder, locations):
if __name__ == '__main__':
- Q = sys.argv[1]
-
# Use your own API key here if you use a geocoding service
# such as Google or Yahoo!
- GEOCODING_API_KEY = sys.argv[2]
+ GEOCODING_API_KEY = sys.argv[1]
+
+ Q = ' '.join(sys.argv[2:])
- MAX_HTTP_ERRORS = 3
+ 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, _ = analyzeUsersInSearchResults(Q)
- locations = screen_name_to_location.values()
+ _, screen_name_to_location, _ = analyze_users_in_search_results(t, Q, 2)
- location2coords, location2description = geocodeLocations(g, locations)
+ locations = screen_name_to_location.values()
+ location2coords, location2description = geocode_locations(g, locations)
View
2 recipe__search.py
@@ -4,7 +4,7 @@
import json
import twitter
-Q = sys.argv[1]
+Q = ' '.join(sys.argv[1])
MAX_PAGES = 15
RESULTS_PER_PAGE = 100
View
1 recipe__streaming_api.py
@@ -5,6 +5,7 @@
import webbrowser
# Query terms
+
Q = sys.argv[1:]
# Get these values from your application settings
View
2 recipe__visualize_rt_graph_graphviz.py
@@ -35,7 +35,7 @@ def write_dot_output(g, out_file):
# Your query
- Q = sys.argv[1]
+ Q = ' '.join(sys.argv[1])
# Your output
View
2 recipe__visualize_rt_graph_protovis.py
@@ -46,7 +46,7 @@ def write_protovis_output(g, out_file, html_template):
# Your query
- Q = sys.argv[1]
+ Q = ' '.join(sys.argv[1])
# How many pages of data to grab for the search results

0 comments on commit ea76254

Please sign in to comment.
Something went wrong with that request. Please try again.