This is a somewhat long homework assignment (do not start too late), as it involves using three separate interfaces - Google's Geocoding API, a Twitter's API, and Google Earth. This homework should be helpful to your final project as well.
Download getcoords.py. This file contains two functions that use google's geohashing API. We want you to play around with these functions, so open the program, and run it.
getCoordinates
function by calling it with the following three strings as input:
printLocation
with the following string inputs:
printLocation
. Edit the end of printLocation
so that it also prints the current city. Retry question two to test your changes. Hint: Another term for city is 'locality'.
getTweetsTimeline
and getTweetsSearch
at the bottom of the file (beneath the line that says MAIN PROGRAM
). Check the results of term.csv and user.csv after using different inputs, you should get see different tweets show up in these files based on where you centered the searches.
'YOUR_RE_HERE'
with a actual regular expression that will successfully find the latitude and longitude from EACH line of the CSV file. The lines of the CSV file are passed one at a time to the function. Your regular expression should contain:
match.group(1)
and match.group(2)
.
Download kmlgen.py, open it, and take a look at the functions. You will be filling them in as described below.
getPlacemark
function. It takes in a name, description, longitude, and latitude. Change it to produce a string that represents a KML Placemark element that can be read by Google Earth. For more details see the template variable in the getPlacemark
function - your output string should be in this format, but with the appropriate pieces replaces with the function's input. getKML
function. This function takes a list of lists, where each inner list is of the form ['text tweet 1', lat, long]
. Edit getKML
to call getPlacemark
using each inner list as input to get a KML Placemark corresponding to each tweet. Once you've done that, combine them all into a single string representing a KML file with multiple placemarks, and return that string.
Take care - there is some extra content in a KML file beyond what getPlacemark
produces, and you'll need too add these pieces to the string you return. Refer to CIT.kml.txt to figure out what else you'll need.
getKML
as input, you'll generate a file that maps the given points and can be opened in Google Earth!getKML
and your new function, add a few lines at the bottom of your code to create a KML file from the array called test_input
. If everything worked, then you should be able to open the resulting .kml file in Google Earth.Rename all four of your files FirstLast_original_file_name.py
, place them all in a folder named FirstLast_HW3-2
and share that folder with .
Note: Before you turn in your Python files, make sure they run properly(Save your Python file. Then select Run > Run Module
or hit F5
on your keyboard)! If nothing appears in the Shell, don't worry as long as no red error messages appear. If they don't run, i.e. if red stuff starts appearing in the shell, points will be taken off!