Google Location History to Country Chart

I had some spare time, so I knocked out another rough and ready set of scripts that I've been meaning to code for a while (see also DenseDead). These scripts, written in python with help from the Google Geocoding API, Google Charts, and the GeoPy module will give you a map of the world with countries colored based on how many years it has been since you visited. Mine looks like this (I added some data by hand for before 2012):

It is kind of kludgy, but in case you are curious, the steps and the scripts are below.

One of the reasons I wanted to write these is because the Google information is awesome but both too detailed for what I'd like to keep lying around, and not useful to me as latitude/longitudes. Instead, I'd like to know the countries I've been to over time. With these scripts, I convert the timestamps and latitude/longitudes into timestamps and addresses before fuzzing them down to years and countries, which is immediately useful and about the level that I want to keep. If you no longer find Google's use of its more fine-grained information useful, you can also clear the more detailed information from Google (instructions to delete your location history).
  1. Go to Google Takeout and download a KML of your location history. Allow me one small digression here.
    Google Takeout exists because of a relatively small group of engineers and others at Google who worked hard to make it exist. The team used to go by the name of the Google Data Liberation Front and have a really cool website and logo. The website now redirects to a support article but there are still great people working at Google working on ensuring that users have access to their data. This type of data portability is extremely important and ensuring it is something I worked on in the private and public sector. Thank you to the current and former team members and allies of the Data Liberation Front!
  2. Run to reduce the number of KML entries to a more manageable number. I threw out all entries that are within 10miles of the last entry I counted. The commandline is:
    #python Google_Location.kml > outfile.kml
  3. Split up the resulting file into chunks so that you don't violate the Google Geocoding API's daily limit. I used "#split -l4000 output_from_reduce.kml infile" that will produce 2000 calls to the Google API per file.
  4. Run on each of the split files. Do one per day so as not to get blocked. The commandline is:
    #PYTHONIOENCODING=utf-8 python input_file.kml
    Note that I needed to specify the encoding because although I think I understand encoding well enough, I don't. If someone else wants to teach me how to fix that, I would love to know.
  5. Join the outputfiles ("#join infileaa infileab infileac > infile_join"). 
  6. Optional: Fuzz the joined outputfiles by using
    #python inputfile.csv outputfile.csv
  7. Run to create an HTML file that will include the javascript for the chart. The commandline is:
    #python input_file.csv > Country_Chart.html
You may download the scripts at amac0/google-location-tools and the most interesting are also below.