This commit is contained in:
Johannes Loher 2017-05-14 11:29:19 +02:00
parent a6aeaa336e
commit c7cf7fedfd
3 changed files with 14 additions and 12 deletions

View file

@ -5,7 +5,7 @@
"Oliver Rümpelein" "Oliver Rümpelein"
], ],
"dependencies": { "dependencies": {
"requests": "~>0.3.1", "requests": "~>0.4.1",
"kxml": "~>1.0.1" "kxml": "~>1.0.1"
}, },
"description": "A minimal D application.", "description": "A minimal D application.",

View file

@ -12,11 +12,8 @@ import fahrplanparser;
import substitution; import substitution;
// find stops: http://mobile.defas-fgi.de/beg/XML_STOPFINDER_REQUEST?outputFormat=XML&stateless=1&locationServerActive=1&regionID_sf=1&type_sf=stop&name_sf=Regensburg%20Universit%C3%A4t
enum baseURL = "http://mobile.defas-fgi.de/beg/"; enum baseURL = "http://mobile.defas-fgi.de/beg/";
enum departureMonitorRequest = "XML_DM_REQUEST"; enum departureMonitorRequest = "XML_DM_REQUEST";
enum stopFinderRequest = "XML_STOPFINDER_REQUEST";
void main(string[] args) void main(string[] args)
{ {

View file

@ -21,6 +21,7 @@ template timeXPath(string _timeNodeName = timeNodeName)
{ {
enum timeXPath = "/st/" ~ _timeNodeName; enum timeXPath = "/st/" ~ _timeNodeName;
} }
enum useRealTimeXPath = "/realtime"; enum useRealTimeXPath = "/realtime";
enum lineXPath = "/m/nu"; enum lineXPath = "/m/nu";
enum directionXPath = "/m/des"; enum directionXPath = "/m/des";
@ -41,8 +42,8 @@ auto parsedFahrplan(in string data)
@system unittest @system unittest
{ {
import std.stdio; import std.array : array;
import std.array: array;
auto xml = ""; auto xml = "";
assert(xml.parsedFahrplan.array == []); assert(xml.parsedFahrplan.array == []);
@ -50,13 +51,17 @@ auto parsedFahrplan(in string data)
assert(xml.parsedFahrplan.array == []); assert(xml.parsedFahrplan.array == []);
xml = "<efa><dps><dp><realtime>1</realtime><st><t>1224</t><rt>1242</rt></st><m><nu>6</nu><des>Wernerwerkstraße</des></m></dp></dps></efa>"; xml = "<efa><dps><dp><realtime>1</realtime><st><t>1224</t><rt>1242</rt></st><m><nu>6</nu><des>Wernerwerkstraße</des></m></dp></dps></efa>";
assert(xml.parsedFahrplan.array == [["direction":"Wernerwerkstraße", "line":"6", "departure":"12:24", "delay":"18"]]); assert(xml.parsedFahrplan.array == [["direction" : "Wernerwerkstraße",
"line" : "6", "departure" : "12:24", "delay" : "18"]]);
xml = "<efa><dps><dp><realtime>0</realtime><st><t>1224</t></st><m><nu>6</nu><des>Wernerwerkstraße</des></m></dp></dps></efa>"; xml = "<efa><dps><dp><realtime>0</realtime><st><t>1224</t></st><m><nu>6</nu><des>Wernerwerkstraße</des></m></dp></dps></efa>";
assert(xml.parsedFahrplan.array == [["direction":"Wernerwerkstraße", "line":"6", "departure":"12:24", "delay":"0"]]); assert(xml.parsedFahrplan.array == [["direction" : "Wernerwerkstraße",
"line" : "6", "departure" : "12:24", "delay" : "0"]]);
xml = "<efa><dps><dp><realtime>0</realtime><st><t>1224</t></st><m><nu>6</nu><des>Wernerwerkstraße</des></m></dp><dp><realtime>1</realtime><st><t>1353</t><rt>1356</rt></st><m><nu>11</nu><des>Burgweinting</des></m></dp></dps></efa>"; xml = "<efa><dps><dp><realtime>0</realtime><st><t>1224</t></st><m><nu>6</nu><des>Wernerwerkstraße</des></m></dp><dp><realtime>1</realtime><st><t>1353</t><rt>1356</rt></st><m><nu>11</nu><des>Burgweinting</des></m></dp></dps></efa>";
assert(xml.parsedFahrplan.array == [["direction":"Wernerwerkstraße", "line":"6", "departure":"12:24", "delay":"0"], ["direction":"Burgweinting", "line":"11", "departure":"13:53", "delay":"3"]]); assert(xml.parsedFahrplan.array == [["direction" : "Wernerwerkstraße", "line" : "6",
"departure" : "12:24", "delay" : "0"], ["direction" : "Burgweinting",
"line" : "11", "departure" : "13:53", "delay" : "3"]]);
} }
private: private:
@ -125,13 +130,13 @@ in
} }
body body
{ {
auto useRealtimeString = dp.parseXPath(useRealTimeXPath).front.getCData; immutable useRealtimeString = dp.parseXPath(useRealTimeXPath).front.getCData;
if (useRealtimeString == "0") if (useRealtimeString == "0")
return dur!"minutes"(0); return dur!"minutes"(0);
else if (useRealtimeString == "1") else if (useRealtimeString == "1")
{ {
auto expectedTime = dp.departureTime; immutable expectedTime = dp.departureTime;
auto realTime = dp.departureTime!realTimeNodeName; immutable realTime = dp.departureTime!realTimeNodeName;
auto timeDiff = realTime - expectedTime; auto timeDiff = realTime - expectedTime;
if (timeDiff < dur!"minutes"(0)) if (timeDiff < dur!"minutes"(0))
timeDiff = dur!"hours"(24) + timeDiff; timeDiff = dur!"hours"(24) + timeDiff;