Fuelly API - Fuelly Forums

Click here to see important news regarding the aCar App

Reply
 
Thread Tools Display Modes
 
Old 10-12-2011, 08:09 AM   #1
Junior Member
 
Join Date: Jul 2011
Posts: 15
Country: United States
Location: Lynn, MA
Fuelly API

Not an API but some PHP Classes to get at your Fuelly Data

I know many people (including myself) wish Fuelly had an API so that we could fetch data and display it inline on our site. The only suggestions I have seen is to export to csv and import to your site or write a script that would login as your user and export/import on it's own.

However this is just messy. I have created a set of PHP classes that use the DOM to get at the data that Fuelly displays in-line on the site. Currently it requires your username and password and fetches your list of vehicles based on that. Once it has a list of vehicles it will loop over them and fetch the data associated with them, along with the last X fuelups, this number is configurable by changing a class constant currently. I know it's not the best way but this code is a work in progress and I will be extending upon it so that everyone who wishes to use it can benefit from it.

You can download and view the code at http://www.josephcrawford.com/wp-con...-0.1-alpha.zip

It's pretty straight forward, basically you create a fuelly_user instance with your username and password. Then you get an instance of the fuelly_scraper class passing it the user and call the run method. It will return a populated user object like the following:

Code:
object(Fuelly_User)#1 (5) {
  ["_email:private"]=>
  string(23) "info@josephcrawford.com"
  ["_password:private"]=>
  string(9) "password"
  ["_displayName:private"]=>
  string(11) "jcrawford27"
  ["_isLoggedIn:private"]=>
  bool(true)
  ["_vehicles:private"]=>
  array(2) {
    ["cbr600rr"]=>
    object(Fuelly_Vehicle)#4 (13) {
      ["_name:private"]=>
      string(8) "cbr600rr"
      ["_id:private"]=>
      string(5) "83630"
      ["_displayName:private"]=>
      NULL
      ["_avgMilesPerGallon:private"]=>
      string(4) "41.6"
      ["_lastMilesPerGallon:private"]=>
      string(4) "41.1"
      ["_bestMilesPerGallon:private"]=>
      string(4) "44.8"
      ["_avgPricePerGallon:private"]=>
      string(5) "$3.94"
      ["_avgPricePerFuelUp:private"]=>
      string(5) "$9.93"
      ["_avgPricePerMile:private"]=>
      string(6) "$0.094"
      ["_totalFuelUps:private"]=>
      string(2) "24"
      ["_totalSpent:private"]=>
      string(7) "$238.37"
      ["_totalMilesTracked:private"]=>
      string(5) "2,313"
      ["_fuelUps:private"]=>
      array(10) {
        [0]=>
        object(Fuelly_Fuelup)#11 (6) {
          ["_timestamp:private"]=>
          string(10) "1318285570"
          ["_odometer:private"]=>
          int(0)
          ["_miles:private"]=>
          string(4) "93.0"
          ["_gallons:private"]=>
          string(4) "2.26"
          ["_milesPerGallon:private"]=>
          string(4) "41.1"
          ["_pricePerGallon:private"]=>
          string(5) "4.019"
        }
    }
    ["highlander"]=>
    object(Fuelly_Vehicle)#3 (13) {
      ["_name:private"]=>
      string(10) "highlander"
      ["_id:private"]=>
      string(5) "93897"
      ["_displayName:private"]=>
      NULL
      ["_avgMilesPerGallon:private"]=>
      string(4) "30.7"
      ["_lastMilesPerGallon:private"]=>
      string(4) "29.5"
      ["_bestMilesPerGallon:private"]=>
      string(4) "32.0"
      ["_avgPricePerGallon:private"]=>
      string(5) "$3.59"
      ["_avgPricePerFuelUp:private"]=>
      string(6) "$46.25"
      ["_avgPricePerMile:private"]=>
      string(6) "$0.117"
      ["_totalFuelUps:private"]=>
      string(1) "2"
      ["_totalSpent:private"]=>
      string(6) "$92.50"
      ["_totalMilesTracked:private"]=>
      string(3) "790"
      ["_fuelUps:private"]=>
      array(2) {
        [0]=>
        object(Fuelly_Fuelup)#13 (6) {
          ["_timestamp:private"]=>
          string(0) ""
          ["_odometer:private"]=>
          int(0)
          ["_miles:private"]=>
          string(5) "400.0"
          ["_gallons:private"]=>
          string(5) "12.50"
          ["_milesPerGallon:private"]=>
          string(4) "32.0"
          ["_pricePerGallon:private"]=>
          string(5) "3.599"
        }
        [1]=>
        object(Fuelly_Fuelup)#25 (6) {
          ["_timestamp:private"]=>
          string(0) ""
          ["_odometer:private"]=>
          int(0)
          ["_miles:private"]=>
          string(5) "390.0"
          ["_gallons:private"]=>
          string(5) "13.23"
          ["_milesPerGallon:private"]=>
          string(4) "29.5"
          ["_pricePerGallon:private"]=>
          string(5) "3.590"
        }
      }
    }
  }
}
Hopefully one-day Fuelly will get an API going so that we can do things like this. I am not personally looking for a way to push data to Fuelly, I basically want to display some data on my site. I was originally going to put on my site how many miles I have driven today based on the fuel-ups for the current date but it will take a bit more work to get all that information.
__________________

jcrawford27 is offline   Reply With Quote
Old 10-12-2011, 08:11 AM   #2
Junior Member
 
Join Date: Jul 2011
Posts: 15
Country: United States
Location: Lynn, MA
I should add that I have not tested this with any countries other than the US. If you find issues trying to use it in your country please let me know.

I will be updating and maintaining this code but am releasing it for anyone to use/share/extend.

if you add improved features I would appreciate it if you could pass that on to me
__________________

jcrawford27 is offline   Reply With Quote
Old 10-12-2011, 08:21 AM   #3
pb
Senior Member
 
Join Date: Jul 2008
Posts: 1,588
Country: United States
Location: Corvallis, OR
Looks interesting, nice work!
pb is offline   Reply With Quote
Old 10-12-2011, 08:22 AM   #4
Junior Member
 
Join Date: Jul 2011
Posts: 15
Country: United States
Location: Lynn, MA
If anyone is wondering why there are none of the mini-stats collected it is because each mini-stat does not have an identifier in the code such as an id/class that I could use with XPath to fetch the data from the dom.

I could still grab the data without them however how am I to know what order the mini-stats are in since every user can put them in any order they wish. Also the script currently only uses cURL to login to get your vehicle list. Everything else is pulled from public pages. I plan to change this in the future so that you can get at the data that is only available to you on the Fuelly site, more to come over the next few weeks.
jcrawford27 is offline   Reply With Quote
Old 10-12-2011, 08:23 AM   #5
Junior Member
 
Join Date: Jul 2011
Posts: 15
Country: United States
Location: Lynn, MA
Thanks pb and I hope you don't mind. I only set off on this venture when I saw your it's ok to scrape the site for personal use in another thread
jcrawford27 is offline   Reply With Quote
Old 10-12-2011, 08:28 AM   #6
pb
Senior Member
 
Join Date: Jul 2008
Posts: 1,588
Country: United States
Location: Corvallis, OR
If you download all fuel-ups for a particular vehicle to a local database anyway you could recreate any of the mini-stats by computing them on your end.
pb is offline   Reply With Quote
Old 10-12-2011, 08:36 AM   #7
Junior Member
 
Join Date: Jul 2011
Posts: 15
Country: United States
Location: Lynn, MA
yep I plan to try to make it store them locally so that I have to reach out to Fuelly once a day for new data.

I've only been working on this code for a few hours today so it's just the beginning

However when it comes to the mini-stats I would not know what stat is what because there are no id/class to identify by. I guess I could compare against the labels but that would only work for english

It would be nice if you could do something like this on your end.

<div id="stats-mini">

<ul>

<li id="avg-miles-fuelup">

<strong>105.1</strong>

<em>All Time</em>

<p>Avg Miles/Fuel-up</p>

</li>

<li id="total-gallongs-consumed">

<strong>60.54</strong>

<em>All Time</em>

<p>Gallons Consumed</p>

</li>

<li id="best-price-gallon">

<strong>

<em>All Time</em>

<p>Best Price/Gallon</p>

</li>

</ul>

<div style="clear:both;">

</div>

If it had those id's or something similar I could fetch them with //div[@id='mini-stats']/li[@id='best-price-gallon']
jcrawford27 is offline   Reply With Quote
Old 10-12-2011, 08:38 AM   #8
Junior Member
 
Join Date: Jul 2011
Posts: 15
Country: United States
Location: Lynn, MA
as for computing them on my end sure it could be done but i found that my numbers come out different than yours. I found that in the simple case where I tried to calculate total fuelup cost as gallons * price. could not get the exact number you have in the stats on the actual fuelup page.

I opted to use the datatables JSON output you have available rather than scraping for all the fuelups, maybe I will change that soon.
jcrawford27 is offline   Reply With Quote
Old 10-12-2011, 08:49 AM   #9
pb
Senior Member
 
Join Date: Jul 2008
Posts: 1,588
Country: United States
Location: Corvallis, OR
It would be nice if you could do something like this on your end.

True, but you never know what people have set as their mini-stats. So you'd only have access to whatever stats the user has enabled.

Can't you get the stat from the DOM? Each mini stat includes the value, label, and the timeframe. The strong tag has the value, the em tag has the timeframe, and the p tag has the stat name. You should be able to get it without IDs.
pb is offline   Reply With Quote
Old 10-12-2011, 09:03 AM   #10
Junior Member
 
Join Date: Jul 2011
Posts: 15
Country: United States
Location: Lynn, MA
sure can but is your site multi-lingual? If so that would lead to one hell of a conditional comparing labels
__________________

jcrawford27 is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


» Fuelly Android Apps
No Threads to Display.
Powered by vBadvanced CMPS v3.2.3


All times are GMT -8. The time now is 06:54 PM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.