Python Modules Needed
You will need to install some Python modules if you have not authenticated to the Google APIs before. Here is a list of modules I installed.
- requests
- urllib3
- apiclient
- gspread
- PyOpenSSL
- oauth2client
- google-api-python-client (used easy_install)
Not all of these are needed for the script. I am working from a new laptop so I had install them fresh. All of these were installed using pip except the Google API Python client. For some reason pip did not install that so we had to use easy_install.
Authentication
We used the same method detailed in this earlier post using the gspread module. You will want to create the JSON file with your authentication key in it so you can authenticate to the Fusion Table API.
Make sure you grant your client email address access to edit the Fusion table. You can do this using the Fusion Table Share feature and then add the email from the JSON file you downloaded when you built your key XXXXXXXXXXXXXXX@developer.gserviceaccount.com
Make sure you grant your client email address access to edit the Fusion table. You can do this using the Fusion Table Share feature and then add the email from the JSON file you downloaded when you built your key XXXXXXXXXXXXXXX@developer.gserviceaccount.com
Script
I am using the USGS Earthquake JSON feed I blogged about earlier today to import Earthquake data in to a Fusion Table. Here is the script.
Basically we just setup a loop to parse the Earthquake JSON data and on each loop we execute an INSERT statement in Fusion. Again there is probably a better way than the line by line method detailed here. But again at least we can import data into Fusion. This is not going to be practical for thousands of rows but is fine for our purpose here.
Link to the Fusion Table Map:
https://www.google.com/fusiontables/embedviz?q=select+col4+from+1aXGZQoukkHHSAKSHuCakYuVbh2qSaBxN5C-APpOE&viz=MAP&h=false&lat=17.868051231860818&lng=-24.377267187500024&t=1&z=2&l=col4&y=2&tmplt=2&hml=TWO_COL_LAT_LNG
Link to the Fusion Table Map:
https://www.google.com/fusiontables/embedviz?q=select+col4+from+1aXGZQoukkHHSAKSHuCakYuVbh2qSaBxN5C-APpOE&viz=MAP&h=false&lat=17.868051231860818&lng=-24.377267187500024&t=1&z=2&l=col4&y=2&tmplt=2&hml=TWO_COL_LAT_LNG
0 comments:
Post a Comment