Automating Fuel Mileage Tracking with PHP and Google Spreadsheets

Pump Fill-up Form

Ever since I started driving, I've been in the habit of tracking my fill-up cost at the gas station. The problem was that I never used this data. About 6 months ago, I created a Google Spreadsheet to track this data. Using a built-in form, I could enter in this data at the time of the fill-up by using my smartphone. Excellent!

The spreadsheet forms, while useful, are very basic. Furthermore, there was no good way to view historical data from my phone.

Using the Zend Gdata library and some simple scripting, I've developed a simple, mobile-friendly (albeit ugly) UI for entering your fuel mileage. It is live right now at gas.randomland.net (/m for mobile the version).

The 'stats' screen

Once you've entered your data, you'll be taken to a stats page. This gives a quick overview of how this fill-up compares with previous ones.

 

To get started, copy this master document to your Google Docs. Go to gas.randomland.net; you'll be asked to authorize access to your Google Docs account. Once you accept, the app will display spreadsheets in your Google Docs which end in "(rlgaslog)"; so name it accordingly. Right now, the PHP scripts are hosted on Randomland, but could be hosted anywhere.

It still has quirks (such as the annoying auth method), but it is a work in progress. If you have any suggestions, please leave a comment or send me an email. Full source code is available in the repository. Thanks!

Comments

Awesome

This is unexspected and awesome. I had no idea you were working on it. I, for one, will be giving this a try. So far all I have to tracking my millage is a hand full of gas recipts with some scribbles on them.

Not that my millages ever changes much.

Cool, yoes

Cool. Let me know what bugs or annoyances you find. It'll help, even if I'm the only one who uses it Smile The biggest thing I know I need to fix is the authorization method. Every time your browser session expires, you will be asked to authorize access to your Google account again. From what I've read, I need switch from AuthSub to OAuth.

Mobile site

Thanks a lot for this, Z.  I've been using Excel to keep track for a couple of years but I like the idea of keeping the record online much better.

I kicked things off by playing catchup and putting in my last 20 entries last night.  Twice, after submitting the data I received an error (can't remember exactly what it was now but I'll come back and post if I get it again) but realized that the data had made it into the doc so I ignored it and moved on.

I'm excited about the possibility of entering data while on the road, and the standard entry page works ok but I just get the following 'auth' error on the mobile site:


Warning: require_once(scripts/auth.php) [function.require-once]: failed to open stream: No such file or directory in /var/www/gas/scripts/globals.php on line 38

Fatal error: require_once() [function.require]: Failed opening required 'scripts/auth.php' (include_path='.:/php/includes:/usr/local/lib/zendgdata/library') in /var/www/gas/scripts/globals.php on line 38

Does this pertain to what you already mentioned about using OAuth rather than AuthSub?


Sorry!

anonymous, I'm really sorry I didn't see this earlier...we are really to unaccustomed legitimate comments! Smile At any rate, the issue has been fixed. I totally redid the system using a jQuery Mobile front end. It's slower, but a lot better in just about every other aspect. URL is the same.

As for that error...I know. The original code had some really, really bad authentication code. In fact, that's the reason I started over. My session token expired and I was stuck in a state where I could not log in because I hadn't bothered to write the code to log out...doh!

If you're still interested, check out the new UI, still avalibale from gas.randomland.net. The code is now posted on github.com/zourtney/mobilemiles. Again, sorry about all that. If you need any pointers, shoot me an email at zourtney at randomland dot net.