Skip to content
Snippets Groups Projects
Commit 52cc7843 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

Module: OBB speed and next_stop

parent 7550b6ac
No related branches found
No related tags found
No related merge requests found
...@@ -386,3 +386,47 @@ class ParserCDNextStop: Parser ...@@ -386,3 +386,47 @@ class ParserCDNextStop: Parser
} }
#pragma warning restore 8602 #pragma warning restore 8602
} }
[ParserName("OBB_speed")]
class ParserOBBSpeed: Parser
{
#pragma warning disable 8602
public void Init(ModuleParent _bar, Module _module, ConfigSection section)
{
}
public IEnumerable<Block> Parse(string data)
{
return new Block[]{new Block($"{data} km/h", Color: Color.White)};
}
#pragma warning restore 8602
}
[ParserName("OBB_next_stop")]
class ParserOBBNextStop: Parser
{
#pragma warning disable 8602
public void Init(ModuleParent _bar, Module _module, ConfigSection section)
{
}
public IEnumerable<Block> Parse(string data)
{
try
{
JsonObject json = JsonObject.Parse(data).AsObject();
JsonObject nextStop = json["currentStation"].AsObject();
string nextStopName = nextStop["name"].AsObject()["all"].GetValue<string>();
DateTime nextStopArrival = DateTime.Parse(nextStop.AsObject()["arrivalForecast"]?.GetValue<string>());
DateTime nextStopArrivalScheudled = DateTime.Parse(nextStop.AsObject()["arrivalSchedule"]?.GetValue<string>());
long arrivalIn = (long)(nextStopArrival - DateTime.Now).TotalSeconds;
int delay_s = (int)(nextStopArrival - nextStopArrivalScheudled).TotalSeconds;
string delayStr = delay_s==0?"":$" ({TimeShow.WithSign(delay_s)})";
return new Block[]{new Block($"{nextStopName} in {TimeShow.Show(arrivalIn)}"+delayStr, Color: Color.White)};
}
catch(Exception e)
{
Console.Error.WriteLine(e);
return new Block[]{new Block("OBB PE", Color: Color.Red)};
}
}
#pragma warning restore 8602
}
...@@ -441,3 +441,26 @@ period = 20 ...@@ -441,3 +441,26 @@ period = 20
show_old = 60 show_old = 60
max_old = 300 max_old = 300
_exec = chromium http://cdwifi.cz _exec = chromium http://cdwifi.cz
# Parser: OBB_speed and OBB_next_stop
# -----------------------------------
# Show information about the speed or next stop and delay for Österreichische Bundesbahnen trains.
# Example usage:
[OBB_speed]
_type=http
url = https://railnet.oebb.at/api/speed
period = 5
show_old = 20
max_old = 120
error_handler =
no_data_handler =
_exec = chromium http://railnet.oebb.at/
[OBB_next_stop]
_type=http
url = https://railnet.oebb.at/assets/modules/fis/combined.json
error_handler =
period = 20
show_old = 60
max_old = 300
_exec = chromium http://railnet.oebb.at/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment