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"
],
"dependencies": {
"requests": "~>0.3.1",
"requests": "~>0.4.1",
"kxml": "~>1.0.1"
},
"description": "A minimal D application.",

View file

@ -12,11 +12,8 @@ import fahrplanparser;
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 departureMonitorRequest = "XML_DM_REQUEST";
enum stopFinderRequest = "XML_STOPFINDER_REQUEST";
void main(string[] args)
{

View file

@ -21,6 +21,7 @@ template timeXPath(string _timeNodeName = timeNodeName)
{
enum timeXPath = "/st/" ~ _timeNodeName;
}
enum useRealTimeXPath = "/realtime";
enum lineXPath = "/m/nu";
enum directionXPath = "/m/des";
@ -41,8 +42,8 @@ auto parsedFahrplan(in string data)
@system unittest
{
import std.stdio;
import std.array : array;
auto xml = "";
assert(xml.parsedFahrplan.array == []);
@ -50,13 +51,17 @@ auto parsedFahrplan(in string data)
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>";
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>";
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>";
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:
@ -125,13 +130,13 @@ in
}
body
{
auto useRealtimeString = dp.parseXPath(useRealTimeXPath).front.getCData;
immutable useRealtimeString = dp.parseXPath(useRealTimeXPath).front.getCData;
if (useRealtimeString == "0")
return dur!"minutes"(0);
else if (useRealtimeString == "1")
{
auto expectedTime = dp.departureTime;
auto realTime = dp.departureTime!realTimeNodeName;
immutable expectedTime = dp.departureTime;
immutable realTime = dp.departureTime!realTimeNodeName;
auto timeDiff = realTime - expectedTime;
if (timeDiff < dur!"minutes"(0))
timeDiff = dur!"hours"(24) + timeDiff;