[-]
[+]
|
Changed |
_service:tar_git:harbour-spritradar-0.2.3.tar.bz2/qml/pages/Plugin/PrixCarburants.qml
^
|
@@ -9,11 +9,17 @@
description: "https://www.prix-carburants.gouv.fr/"
units: { "currency":"€", "distance": "km" }
countryCode: "fr"
- property string url: "http://harbour-spritradar-fork.w4f.eu/fr/"
+ //property string url: "http://harbour-spritradar-fork.w4f.eu/fr/"
+ property string url: "https://api.prix-carburants.2aaz.fr"
type: "e10"
- types: ["Gazole", "SP95", "E10", "E85", "GPLc", "SP98"]
+ types: ["Gazole", "SP95", "SP95-E10", "E85", "GPLc", "SP98"]
names: [qsTr("Gazole"), qsTr("SP95"), qsTr("E10"), qsTr("E85"), qsTr("GPLc"), qsTr("SP98")]
+ function betweenHours(h0, h1) {
+ var now = new Date();
+ var mins = now.getHours()*60 + now.getMinutes();
+ return toMins(h0) <= mins && mins <= toMins(h1);
+ }
settings: Settings {
name: "PrixCarburants"
@@ -64,26 +70,45 @@
itemsBusy = true
items.clear()
coverItems.clear()
+ var now = new Date()
+ var day = now.getDay()
var req = new XMLHttpRequest()
- req.open( "GET", url+"?get=stations&lat="+lat+"&lng="+lng+"&radius="+searchRadius )
+ // search radius is now via a header -H 'Range: m=5000-7000'
+ req.open( "GET", url+"/stations/around/"+lat+","+lng+"?types=R,A&responseFields=Fuels,Price,Hours")
+ req.setRequestHeader("accept", "application/json")
+ req.setRequestHeader("Range", "m=100-"+searchRadius*1000)
req.onreadystatechange = function() {
if( req.readyState == 4 ) {
try {
var x = JSON.parse( req.responseText )
for( var i = 0; i < x.length; i++ ) {
var o = x[i]
- var price = { price:0 }
- for( var j = 0; j < o.prices.length; j++ ) {
- if( o.prices[j].id == type ) price = o.prices[j]
+ var price = 0
+ var open = false
+ //console.log(o.type)
+ for( var j = 0; j < o.Fuels.length; j++ ) {
+ //console.log(o.Fuels[0]["short_name"])
+ if( o.Fuels[j]["short_name"] == type ) {
+ price = o.Fuels[j]["Price"]["value"]
+ }
+ }
+ try {
+ if( o.Hours["Days"][day-1]["status"] == "open" ) {
+ open = true
+ }
+ } catch(e) {
+ console.log(e.message)
}
- if( price.price == 0 ) continue
+
+ if( price == 0 || open == false) continue
+
var itm = {
"stationID": o.id,
- "stationName": o.adresse,
- "stationPrice": price.price,
- "stationAdress": o.adresse,
- "stationDistance": o.distance*1000,
- "customMessage": false
+ "stationName": o["Brand"]["name"],
+ "stationPrice": price,
+ "stationAdress": o["Address"]["street_line"],
+ "stationDistance": o.distance,
+ "customMessage": !open?qsTr("Closed"):qsTr("Open")
}
items.append( itm )
}
@@ -107,32 +132,49 @@
station = {}
stationPage = pageStack.push( "../GasStation.qml", {stationId:id} )
var req = new XMLHttpRequest()
- req.open( "GET", url+"?get=station&id="+id )
+ req.open( "GET", url+"/station/"+id )
+ req.setRequestHeader("accept", "application/json")
req.onreadystatechange = function() {
if( req.readyState == 4 ) {
try {
var st = JSON.parse( req.responseText )
+ //console.log( JSON.stringify(st))
var price = []; var service = []
- for( var j = 0; j < st.prices.length; j++ ) {
+ /*for( var j = 0; j < st.prices.length; j++ ) {
try {
price[price.length] = { "title":qsTr(names[types.indexOf(st.prices[j].id)]), "price":st.prices[j].price, "sz":Theme.fontSizeLarge, "tf":true }
} catch( ex ) {
console.log( JSON.stringify(st))
}
+ }*/
+ for( var j = 0; j < st.Fuels.length; j++ ) {
+ try {
+ price[price.length] = {
+ "title":st.Fuels[j]["short_name"],
+ "price":st.Fuels[j]["Price"].value,
+ "sz":Theme.fontSizeLarge, "tf":true }
+ } catch( ex ) {
+ console.log( JSON.stringify(st))
+ }
}
- for( j = 0; j < st.services.length; j++ ) {
- service[service.length] = { title:"",text:st.services[j] }
+
+ for(var j = 0; j < st["Services"].length; j++ ) {
+ var entry = { title:"", text:st["Services"][j] }
+ service.push(entry)
}
- var optimes = st.openingtimes.length>0?[ {title:qsTr("Daily"), "text":st.openingtimes[0].from+"-"+st.openingtimes[0].to }, {title:qsTr("Except"), "text":st.openingtimes[0].except?st.openingtimes[0].except:"-" } ]: []
+ var optimes = [
+ { title:qsTr("Daily"),
+ "text":st["Hours"]["Days"][0]["TimeSlots"][0].opening_time+"-"+st["Hours"]["Days"][0]["TimeSlots"][0].closing_time },
+ { title:qsTr("Except"), "text": "-" } ]
station = {
+ "stationName": st["Brand"]["name"],
"stationID":st.id,
- "stationName":st.adresse,
"stationAdress": {
- "street": st.adresse,
- "county":st.ville,
+ "street": st["Address"]["street_line"],
+ "county": st["Address"]["city_line"],
"country":"",//country,
- "latitude":st.latitude,
- "longitude":st.longitude
+ "latitude":st["Coordinates"]["latitude"],
+ "longitude":st["Coordinates"]["longitude"],
},
"content": [
{ "title":qsTr("Opening times"), "items":optimes },
@@ -155,15 +197,21 @@
function getPriceForFav( id ) {
var req = new XMLHttpRequest()
- req.open( "GET", url+"?get=station&id="+id )
+ req.open( "GET", url+"/station/"+id )
+ req.setRequestHeader("accept", "application/json")
req.onreadystatechange = function() {
if( req.readyState == 4 ) {
try {
- var o = JSON.parse( req.responseText )
var price = 0
- for( var j = 0; j < o.prices.length; j++ ) {
- if( o.prices[j].id == type ) price = o.prices[j].price
+ var st = JSON.parse( req.responseText )
+ for( var j = 0; j < st.Fuels.length; j++ ) {
+ try {
+ price = st.Fuels[j]["Price"].value;
+
+ } catch( ex ) {
+ console.log( JSON.stringify(st))
}
+ }
if( price == 0) return
setPriceForFav( id, price )
}
|