mirror of https://github.com/deavmi/loadshedd
Initial commit
This commit is contained in:
commit
aaadf0f1b6
|
@ -0,0 +1,17 @@
|
|||
.dub
|
||||
docs.json
|
||||
__dummy.html
|
||||
docs/
|
||||
/loadshedd
|
||||
loadshedd.so
|
||||
loadshedd.dylib
|
||||
loadshedd.dll
|
||||
loadshedd.a
|
||||
loadshedd.lib
|
||||
loadshedd-test-*
|
||||
*.exe
|
||||
*.pdb
|
||||
*.o
|
||||
*.obj
|
||||
*.lst
|
||||
dub.selections.json
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"server": "https://eskom-calendar-api.shuttleapp.rs/v0.0.1/",
|
||||
"area": "western-cape-worscester",
|
||||
"warnBefore": 1,
|
||||
"refreshInterval" : 1
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"authors": [
|
||||
"Tristan B. Velloza Kildaire"
|
||||
],
|
||||
"copyright": "Copyright © 2023, Tristan B. Velloza Kildaire",
|
||||
"dependencies": {
|
||||
"dlog": "~>0.0.6",
|
||||
"eskomcalendar4d": "~>0.1.1",
|
||||
"jstruct": "~>0.1.3"
|
||||
},
|
||||
"description": "The loadshedding daemon for Saffers!",
|
||||
"license": "GPL v3",
|
||||
"name": "loadshedd"
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
module loadshedd.app;
|
||||
|
||||
import loadshedd.config;
|
||||
import std.stdio;
|
||||
import eskomcalendar;
|
||||
import core.thread : Thread, dur, Duration;
|
||||
import std.datetime.systime : Clock, SysTime;
|
||||
|
||||
void main()
|
||||
{
|
||||
Config config = Config.fromJSON2(getJSON("config.json"));
|
||||
EskomCalendar calendar = new EskomCalendar(config.server);
|
||||
|
||||
while(true)
|
||||
{
|
||||
// Get schedules for your area today
|
||||
Schedule[] todayShedding = calendar.getTodaySchedules(config.area);
|
||||
writeln("Schedules for today:\n");
|
||||
|
||||
Schedule[] careAbouts;
|
||||
foreach(Schedule schedule; todayShedding)
|
||||
{
|
||||
writeln(schedule);
|
||||
|
||||
SysTime currentTime = Clock.currTime();
|
||||
currentTime += dur!("minutes")(config.warnBefore);
|
||||
|
||||
// TODO: Figure out the algo
|
||||
|
||||
|
||||
}
|
||||
|
||||
writeln("End of schedules");
|
||||
|
||||
writeln("Care abouts: ", careAbouts);
|
||||
|
||||
|
||||
Thread.sleep(dur!("minutes")(config.refreshInterval));
|
||||
}
|
||||
}
|
||||
|
||||
import std.json : parseJSON, JSONValue;
|
||||
private JSONValue getJSON(string path)
|
||||
{
|
||||
// JSONValue jsonConfig;
|
||||
|
||||
File configFile;
|
||||
configFile.open(path);
|
||||
|
||||
byte[] data;
|
||||
data.length = configFile.size();
|
||||
configFile.rawRead(data);
|
||||
configFile.close();
|
||||
|
||||
return parseJSON(cast(string)data);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
module loadshedd.config;
|
||||
|
||||
import std.json : JSONValue, JSONException;
|
||||
import jstruct;
|
||||
|
||||
public struct Config
|
||||
{
|
||||
public string server;
|
||||
public string area;
|
||||
public long warnBefore;
|
||||
public long refreshInterval;
|
||||
|
||||
public static fromJSON2(JSONValue json)
|
||||
{
|
||||
return fromJSON!(Config)(json);
|
||||
}
|
||||
}
|
||||
|
||||
version(unittest)
|
||||
{
|
||||
import std.json : parseJSON;
|
||||
import std.stdio;
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
JSONValue testConfig = parseJSON(`
|
||||
{
|
||||
"server": "https://eskom-calendar-api.shuttleapp.rs/v0.0.1/",
|
||||
"area": "western-cape-worscester",
|
||||
"warnBefore": 1,
|
||||
"refreshInterval" : 1
|
||||
}
|
||||
`);
|
||||
|
||||
Config config = Config.fromJSON2(testConfig);
|
||||
writeln(config);
|
||||
|
||||
}
|
Loading…
Reference in New Issue