Updating Google Fusion Tables from a CSV File Using Python
My Quality of Life Dashboard project is using Fusion Tables, and I needed to update the table from a CSV. I did it in Python, and it is not a work of art, but I figured someone might find it useful.
First, you’ll need to grab the Fusion Tables python scripts. They don’t have a download or instructions on their site, and if you don’t have subversion handy to check out the repo, here’s what you need to do.
- Pick a folder where your python script is going to sit. Make a folder called "authorization" inside of it.
- Head to the source code for the main trunk.
- Make a file called ftclient.py in your main folder, and paste in the contents of that file from Google Code.
- Go the the authorization folder in the source code browser and look at clientlogin.py. Make the same name file in your authorization folder and copy in the contents.
- Make an empty _init_.py folder in the authorization folder. This will make it so you can import libraries from that folder in your script.
Edit: For easier download of SVN or GIT repos without installing said binaries on Windows, check out Download SVN.
You should be set up to do a little Fusion Tables work. There are more files you can grab for Oath, a file importer and a SQL statement builder, but for my purposes those weren’t necessary.
Here is my python script to update from a CSV. Note that to update a record in GFT requires 2 SQL calls - one to get the ROWID, and another to run the update command with the ROWID as the WHERE clause. Not terribly efficient, but it is what it is.
I make some assumptions about my CSV, which I documented in the code. This is just to get you started and you’ll need to tweak it to meet your needs. Note you’re updating a record at a time to the “cloud”. Grab a cup of coffee if you have a large table.