diff --git a/Assignments/Assignment_15_1 b/Assignments/Assignment_15_1 new file mode 100644 index 0000000..3ec72e5 --- /dev/null +++ b/Assignments/Assignment_15_1 @@ -0,0 +1,25 @@ +Calling a JSON API +In this assignment you will write a Python program somewhat similar to http://www.pythonlearn.com/code/geojson.py. The program will prompt for a location, contact a web service and retrieve JSON for the web service and parse that data, and retrieve the first place_id from the JSON. A place ID is a textual identifier that uniquely identifies a place as within Google Maps. +API End Points +To complete this assignment, you should use this API endpoint that has a static subset of the Google Data: +http://python-data.dr-chuck.net/geojson + + +This API uses the same parameters (sensor and address) as the Google API. This API also has no rate limit so you can test as often as you like. If you visit the URL with no parameters, you get a list of all of the address values which can be used with this API. +To call the API, you need to provide a sensor=false parameter and the address that you are requesting as the address= parameter that is properly URL encoded using the urllib.urlencode() fuction as shown in http://www.pythonlearn.com/code/geojson.py +Just for fun, you can also test your program with the real Google API: +http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=University+of+Michigan + + +Singe Google's data is always changing, the data returned from the Google API could easily be different than from my local copy API. And the Google API has rate limits. But your code should work with the Google API with no modifications other than the base URL. +Test Data / Sample Execution +You can test to see if your program is working with a location of "South Federal University" which will have a place_id of "ChIJJ8oO7_B_bIcR2AlhC8nKlok". +$ python solution.py +Enter location: South Federal University +Retrieving http://... +Retrieved 2101 characters +Place id ChIJJ8oO7_B_bIcR2AlhC8nKlok + + +Turn In +Please run your program to find the place_id for "University of Connecticut" and enter the place_id and your Python code below. Hint: The first seven characters of the place_id are "ChIJGbL ..." diff --git a/Assignments/Assignment_15_2 b/Assignments/Assignment_15_2 new file mode 100644 index 0000000..c776065 --- /dev/null +++ b/Assignments/Assignment_15_2 @@ -0,0 +1,37 @@ +Extracting Data from JSON +In this assignment you will write a Python program somewhat similar to http://www.pythonlearn.com/code/json2.py. The program will prompt for a URL, read the JSON data from that URL using urlliband then parse and extract the comment counts from the JSON data, compute the sum of the numbers in the file and enter the sum below: +We provide two files for this assignment. One is a sample file where we give you the sum for your testing and the other is the actual data you need to process for the assignment. +Sample data: http://python-data.dr-chuck.net/comments_42.json (Sum=2553) +Actual data: http://python-data.dr-chuck.net/comments_242238.json (Sum ends with 77) + +You do not need to save these files to your folder since your program will read the data directly from the URL. Note: Each student will have a distinct data url for the assignment - so only use your own data url for analysis. +Data Format +The data consists of a number of names and comment counts in JSON as follows: +{ + comments: [ + { + name: "Matthias" + count: 97 + }, + { + name: "Geomer" + count: 97 + } + ... + ] +} + + +The closest sample code that shows how to parse JSON and extract a list is json2.py. You might also want to look at geoxml.py to see how to prompt for a URL and retrieve data from a URL. +Sample Execution +$ python solution.py +Enter location: http://python-data.dr-chuck.net/comments_42.json +Retrieving http://python-data.dr-chuck.net/comments_42.json +Retrieved 2733 characters +Count: 50 +Sum: 2482 + + +Turning in the Assignment +Enter the sum from the actual data and your Python code below: +Sum: (ends with 77) \ No newline at end of file