NEWS
Tankstellenliste
-
Hallo,
ich habe mich mal an einer Tankstellenanzeige versucht:
[{"id":"c6eb1ad7.3914e8","type":"http request","name":"askBing","method":"GET","ret":"obj","url":"","x":413,"y":369.7777099609375,"z":"9d75e464.628a18","wires":[["fe754287.018ac","97911695.686ee8","d7d0a190.282f6"]]},{"id":"e64b7305.19b49","type":"function","name":"extractData","func":"/*\n{\n \"license\": \"CC BY 4.0 - http://creativecommons.tankerkoenig.de\",\n \"data\": \"MTS-K\",\n \"station\": {\n \"id\": \"e6aaa4e0-5876-4e05-a564-fb949df831e7\",\n \"name\": \"AVIA Xpress Station\",\n \"brand\": \"AVIA Xpress\",\n \"street\": \"Klingenstraße\",\n \"houseNumber\": \"123\",\n \"postCode\": 70188,\n \"place\": \"Stuttgart\",\n \"overrides\": [],\n \"isOpen\": true,\n \"e5\": 1.419,\n \"e10\": 1.379,\n \"diesel\": 1.269,\n \"lat\": 48.782307,\n \"lng\": 9.209079,\n \"state\": null,\n \"openingTimes\": [\n {\n \"text\": \"täglich ausser Feiertag\",\n \"start\": \"00:00:00\",\n \"end\": \"00:00:00\"\n }\n ]\n }\n}\n*/\n\nvar short = ''+msg.payload.station.brand+\" \"+msg.payload.station.name+\"(\"+msg.payload.station.place+\")\";\nmsg.payload.short=short;\nvar msgTraffic = [\n {\n topic: msg.topic_prefix + \".name\",\n payload: msg.payload.station.name\n },\n {\n topic: msg.topic_prefix + \".brand\",\n payload: msg.payload.station.brand\n },\n {\n topic: msg.topic_prefix + \".street\",\n payload: msg.payload.station.street + \" \" + msg.payload.station.houseNumber\n },\n {\n topic: msg.topic_prefix + \".ort\",\n payload: msg.payload.station.postCode + \" \" + msg.payload.station.place\n },\n {\n topic: msg.topic_prefix + \".e5\",\n payload: msg.payload.station.e5\n },\n {\n topic: msg.topic_prefix + \".e10\",\n payload: msg.payload.station.e10\n },\n {\n topic: msg.topic_prefix + \".diesel\",\n payload: msg.payload.station.diesel\n },\n {\n topic: msg.topic_prefix + \".openingTimes\",\n payload: msg.payload.station.openingTimes\n },\n { \n topic: msg.topic_prefix + \".short\",\n payload: short\n }\n];\n\nreturn [msgTraffic,short,msg];","outputs":"3","noerr":0,"x":250.5555419921875,"y":664.8887939453125,"z":"9d75e464.628a18","wires":[["e358b172.1ca75","dffede6e.20012"],["29d1ab8c.d62e54"],["3fa5fc86.c05a04"]]},{"id":"acf30c31.530cf","type":"inject","name":"Trigger","topic":"","payload":"","payloadType":"date","repeat":"600","crontab":"","once":false,"x":134.88883209228516,"y":113.77778434753418,"z":"9d75e464.628a18","wires":[["9bd6b16d.64295"]]},{"id":"1c5d0fb.fe3a2f","type":"function","name":"defineTankstellen","func":"\nmsg.tanken = [\n {\n id: \"82622c60-8aa2-4822-8f12-bf82c1070a67\",\n name: 'ShellBadNenndorf'\n },\n {\n id: \"005056ba-7cb6-1ed2-bceb-9a84130f4d3b\",\n name: 'StarB65'\n },\n {\n id: \"714c3a0b-cf5d-4c08-9be8-83a3f00fc8d1\",\n name: 'FreieBadNenndorf'\n },\n {\n id: \"7ee9eecc-2548-42b2-8252-b8a42864c930\",\n name: 'AutoHofBadNenndorf'\n },\n {\n id: \"eb782d38-5bae-4fe3-b7ce-3eec5604c74a\",\n name: 'FreieBarsinghausen'\n },\n {\n id: \"005056ba-7cb6-1ed2-bceb-bb7cc667ed4e\",\n name: 'StarBarsinghausen'\n },\n {\n id: \"07de1244-c871-46f3-9bae-62ca73ebdfef\",\n name: 'RakelbuschObi'\n },\n {\n id: \"e1a15081-25d2-9107-e040-0b0a3dfe563c\",\n name: 'HEMBarsinghausen'\n },\n {\n id: \"25c37a76-3ba9-4aa9-8e09-b37c43294eb5\",\n name: 'AralRicklingerKreisel'\n },\n {\n id: \"31cf24f7-4995-424b-9cc1-be54e9bfc879\",\n name: 'CleanCarHildesheimer'\n },\n {\n id: \"f8aaaee6-8809-4f36-a834-d70f4ec7205b\",\n name: 'WestfalenHildesheimer'\n },\n {\n id: \"4446f625-5602-426b-a197-4f4484c4b851\",\n name: 'ShellHannoverKrankenhaus'\n },\n {\n id: \"51d4b4be-a095-1aa0-e100-80009459e03a\",\n name: 'JetMesse'\n },\n {\n id: \"22ce1b68-fce0-4159-8723-d0b63da6a996\",\n name: 'RatioLaatzen'\n },\n {\n id: \"005056ba-7cb6-1ed2-bceb-5a5114dc8d18\",\n name: 'STARRonnenberg'\n },\n];\n\nreturn msg;","outputs":1,"noerr":0,"x":471.88897705078125,"y":113.77778625488281,"z":"9d75e464.628a18","wires":[["b33d9bdd.4cc268"]]},{"id":"d03bedd3.2fc41","type":"function","name":"prepareIteration","func":"// msg.method = \"GET\";\n\nmsg.url = encodeURI(\"https://creativecommons.tankerkoenig.de/json/detail.php?id=\" + msg.payload.id + \"&apikey=\" + msg.config.tank_key);\nmsg.topic_prefix = msg.config.topic_prefix + msg.payload.name;\nmsg.name = msg.payload.name; \nreturn msg;","outputs":1,"noerr":0,"x":251.22222900390625,"y":370.333251953125,"z":"9d75e464.628a18","wires":[["c6eb1ad7.3914e8","7d4d0a40.82b2f4"]]},{"id":"9bd6b16d.64295","type":"function","name":"setConfig","func":"msg.config = {\n tank_key: \"HIER-EIGENER-CODE\",\n topic_prefix: \"node-red.0.tanken.\"\n};\nreturn msg;","outputs":1,"noerr":0,"x":297.11106872558594,"y":114.33332824707031,"z":"9d75e464.628a18","wires":[["1c5d0fb.fe3a2f","dd15a1bb.22ea6"]]},{"id":"b33d9bdd.4cc268","type":"function","name":"loopIds","func":"context.tanken = context.tanken || msg.tanken;\ncontext.liste = context.liste || \"\";\n\nif (msg.payload.short!==undefined) {\n if (context.liste.length>0) {\n context.liste=context.liste+\",\";\n }\n context.liste=context.liste+'{\"SORT\":\"'+msg.payload.station.diesel+'\",\"info\":\"'+ msg.payload.short+'\"}';\n}\n// iterate through all the ids\nif (context.tanken.length > 0) {\n msg.payload = context.tanken.shift();\n return [null, msg];\n}\n\n// Reset routes-context, otherwise we immediately stop in the next run\ncontext.tanken = false;\ncontext.liste=\"[\"+context.liste+\"]\";\n\nvar toSort = eval(context.liste);\ntoSort.sort(function(a,b){\n //return a.attributes.OBJECTID - B.attributes.OBJECTID;\n if(a.SORT == b.SORT)\n return 0;\n if(a.SORT < b.SORT)\n return -1;\n if(a.SORT > b.SORT)\n return 1;\n});\ncontext.liste=toSort;\nvar newMsg={ payload: context.liste };\ncontext.liste=false;\n// we are done with the loop\n\nreturn [newMsg, null];","outputs":"2","noerr":0,"x":161.6666259765625,"y":307.99993896484375,"z":"9d75e464.628a18","wires":[["586f9150.a7907","6533fa95.9acc04"],["d03bedd3.2fc41"]]},{"id":"dd15a1bb.22ea6","type":"debug","name":"","active":false,"console":"false","complete":"true","x":681.6666259765625,"y":233.99993896484375,"z":"9d75e464.628a18","wires":[]},{"id":"e358b172.1ca75","type":"debug","name":"Variablen","active":false,"console":"false","complete":"payload","x":676.6666259765625,"y":507.99993896484375,"z":"9d75e464.628a18","wires":[]},{"id":"16164c6.fe9e9b4","type":"catch","name":"","x":669.6666259765625,"y":116,"z":"9d75e464.628a18","wires":[["dd15a1bb.22ea6"]]},{"id":"5c3a194f.a3c5e8","type":"comment","name":"Tankstellen ","info":"Define your config and routes here.","x":450.6666259765625,"y":77,"z":"9d75e464.628a18","wires":[]},{"id":"7d4d0a40.82b2f4","type":"debug","name":"WEB","active":false,"console":"false","complete":"url","x":664,"y":281.77777099609375,"z":"9d75e464.628a18","wires":[]},{"id":"fe754287.018ac","type":"debug","name":"Answer","active":false,"console":"false","complete":"payload","x":674,"y":335.77777099609375,"z":"9d75e464.628a18","wires":[]},{"id":"3fa5fc86.c05a04","type":"delay","name":"Pause","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":326,"y":541.7777709960938,"z":"9d75e464.628a18","wires":[["b33d9bdd.4cc268"]]},{"id":"97911695.686ee8","type":"switch","name":"Error?","property":"payload.license","rules":[{"t":"cont","v":"tankerkoenig"},{"t":"else"}],"checkall":"true","outputs":2,"x":134,"y":539.7777709960938,"z":"9d75e464.628a18","wires":[["e64b7305.19b49"],["3fa5fc86.c05a04"]]},{"id":"d7d0a190.282f6","type":"debug","name":"license","active":false,"console":"false","complete":"payload.license","x":653,"y":379.77777099609375,"z":"9d75e464.628a18","wires":[]},{"id":"c51250cd.3aedb","type":"catch","name":"","x":113,"y":753.7777709960938,"z":"9d75e464.628a18","wires":[["e64b7305.19b49"]]},{"id":"29d1ab8c.d62e54","type":"debug","name":"short","active":false,"console":"false","complete":"true","x":682,"y":575,"z":"9d75e464.628a18","wires":[]},{"id":"586f9150.a7907","type":"debug","name":"shortSave","active":true,"console":"false","complete":"true","x":354,"y":244,"z":"9d75e464.628a18","wires":[]},{"id":"6533fa95.9acc04","type":"ioBroker out","name":"","topic":"tanken_liste","ack":"true","autoCreate":"true","x":360,"y":311,"z":"9d75e464.628a18","wires":[]},{"id":"dffede6e.20012","type":"ioBroker out","name":"tanken","topic":"","ack":"true","autoCreate":"true","x":696,"y":643,"z":"9d75e464.628a18","wires":[]}]
Im Node "defineTankstellen" die ID's der Tankstellen eintragen (findet man am besten auf der Webseite
Wenn man auf "Melden" klickt und dann die URL oben sich ansieht.
Die Tankstellen werden einzeln und als sortierte Liste gespeichert.
Was müßt ihr anpassen:
-
Den API-Key
-
Die Liste der Tankstellen
-
den SORT-KEY, wenn ihr kein Diesel fahrt (loopIDs).
Viel Spaß
PS: Anbei noch das Widget für VIS
[{"tpl":"tplTableBody","data":{"visibility-cond":"==","visibility-val":1,"static_value":"[{\"Title\": \"first\", \"Value\": 1, \"_Description\": \"Value1\"}, {\"Title\": \"second\", \"Value\": 2, \"_Description\": \"Value2\"}]","table_oid":"node-red.0.tanken_liste","colAttr1":"SORT","colName1":"Preis","colCount":"2","colWidth1":"5px","show_scroll":true,"colName2":"Info","colAttr2":"info","colWidth2":""},"style":{"left":"0px","top":"630px","width":"375px","height":"970px","text-align":"","font-size":"medium"},"widgetSet":"basic"}]
-