Uk petrol prices

Poll UK fuel api's and return the stations with cheapest fuel of type require within specified distance

If no fuel of type require then the station is removed also. The units can be km, mile, meter, nmi default mile, distance has a default of 1, can be a float.

[{"id":"fe12ef283c46ba4e","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"distance","v":"10","vt":"num"},{"p":"home","v":"{\"latitude\":50.80153,\"longitude\":0.316918}","vt":"json"},{"p":"fuel","v":"E10","vt":"str"},{"p":"unit","v":"mile","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"https://applegreenstores.com/fuel-prices/data.json\",\"https://fuelprices.asconagroup.co.uk/newfuel.json\",\"https://storelocator.asda.com/fuel_prices_data.json\",\"https://www.bp.com/en_gb/united-kingdom/home/fuelprices/fuel_prices_data.json\",\"https://fuelprices.esso.co.uk/latestdata.json\",\"https://jetlocal.co.uk/fuel_prices_data.json\",\"https://api2.krlmedia.com/integration/live_price/krl\",\"https://www.morrisons.com/fuel-prices/fuel.json\",\"https://moto-way.com/fuel-price/fuel_prices.json\",\"https://fuel.motorfuelgroup.com/fuel_prices_data.json\",\"https://www.rontec-servicestations.co.uk/fuel-prices/data/fuel_prices_data.json\",\"https://api.sainsburys.co.uk/v1/exports/latest/fuel_prices_data.json\",\"https://www.sgnretail.uk/files/data/SGN_daily_fuel_prices.json\",\"https://www.shell.co.uk/fuel-prices-data.html\",\"https://www.tesco.com/fuel_prices/fuel_prices_data.json\"]","payloadType":"json","x":490,"y":6060,"wires":[["ab0d0df2abeee858"]]},{"id":"ab0d0df2abeee858","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":630,"y":6060,"wires":[["1e1b7bed0286ad7c"]]},{"id":"1e1b7bed0286ad7c","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":6060,"wires":[["2ee19cfc3466c7ce"]]},{"id":"2ee19cfc3466c7ce","type":"http request","z":"d1395164b4eec73e","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"User-Agent","keyValue":"","valueType":"other","valueValue":"Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16"},{"keyType":"Accept","keyValue":"","valueType":"application/json","valueValue":""},{"keyType":"Accept-Language","keyValue":"","valueType":"en-GB, en-US, en;q=0.9","valueValue":""}],"x":530,"y":6120,"wires":[["52581137ac93d4de"]]},{"id":"52581137ac93d4de","type":"switch","z":"d1395164b4eec73e","name":"","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"num"}],"checkall":"true","repair":true,"outputs":1,"x":730,"y":6120,"wires":[["bce35881c2b3f73c"]]},{"id":"bce35881c2b3f73c","type":"join","z":"d1395164b4eec73e","name":"","mode":"reduce","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":true,"timeout":"","count":"","reduceRight":false,"reduceExp":"$append($A, $$.payload.stations)","reduceInit":"[]","reduceInitType":"json","reduceFixup":"","x":890,"y":6120,"wires":[["6d2511afd6049cfa"]]},{"id":"6d2511afd6049cfa","type":"function","z":"d1395164b4eec73e","name":"function 156","func":"const distance = (msg.distance || 1);\nconst fuel = (msg.fuel ?? \"E10\");\nconst unit = (msg.unit ?? \"mile\");\nconst home = msg.home;\n\nmsg.payload = msg.payload.filter(obj => {\n    return haversine(\n        home, \n        obj.location,\n        {unit: unit, threshold: distance}\n    ) &&\n    obj.prices[fuel]\n}).sort((a,b) => \n    a.prices[fuel] - b.prices[fuel]\n);\n\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"haversine","module":"haversine"}],"x":1050,"y":6120,"wires":[["f6cc12f4a74b0d62"]]},{"id":"f6cc12f4a74b0d62","type":"debug","z":"d1395164b4eec73e","name":"debug 2581","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1090,"y":6060,"wires":[]}]

Flow Info

Created 2 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x1)
  • debug (x1)
  • function (x1)
  • http request (x1)
  • inject (x1)
  • join (x1)
  • split (x1)
  • switch (x1)

Tags

  • Uk petrol prices distance order
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option