At Get Wrecked we love Google Sheets, it’s an amazing way to have people collaborate on docs. One thing we hate is having to constantly export google docs as CSV and placing them in our server, and using a database like MySQL and training everybody to use a SQL editor doesn’t cut it either.

I came across this handy trick that lets you read Google Sheets directly as raw CSV, so that you can use it in your server to have instant configs, and you can update stuff on the fly without having to restart services. For us, we use it for stuff like Game Configs, bandwidth limits, rate limits, etc. It’s super useful, especially if the dataset is in human readable format. Keep in mind that there is a limit to calls to Google Sheets. You can see it here: https://developers.google.com/apps-script/guides/services/quotas#current_quotas 

Anyways, here’s how to do it

Go into your google sheets, under Share -> Anyone with link can view

Screen Shot 2016-05-10 at 9.03.10 AM.png

Now, you can export it like this as a CSV file. Make sure that you do not leak your key, don’t put it on “Public on the web”, because that makes it indexable. You should be ok with “anyone with link”, as long as you keep the link private, and don’t put any confidential information in the sheets.

https://docs.google.com/spreadsheets/d/YOUR_DOC_KEY/export?format=csv

Now you can read it in your application like this (we use Java):

https://gist.github.com/PimDeWitte/c75bd72ce248a05b2d0370ebe4a51493

The result:

Screen Shot 2016-05-10 at 8.58.36 AM.png

PS: Make sure not to leak your key 🙂

 

Advertisements