diff --git a/source/cartastraccia/config.d b/source/cartastraccia/config.d index bc332ec..2d5867a 100644 --- a/source/cartastraccia/config.d +++ b/source/cartastraccia/config.d @@ -1,6 +1,12 @@ module cartastraccia.config; import pegged.grammar; +import sumtype; + +import core.time; +import std.conv : to; +import std.algorithm : filter; +import std.range; mixin(grammar(ConfigFileParser)); @@ -29,3 +35,58 @@ Newline <- endOfLine / endOfInput `; + +alias RSSFeedList = SumType!(RSSFeed[], InvalidFeeds); + +struct InvalidFeeds +{ + string msg; +} + +struct RSSFeed +{ + string name; + Duration refresh; + string path; + + this(string[] props) @safe + { + name = props[0]; + path = props[3]; + + switch(props[2][0]) { + case 's': + refresh = dur!"seconds"(props[1].to!uint); + break; + case 'm': + refresh = dur!"minutes"(props[1].to!uint); + break; + case 'h': + refresh = dur!"hours"(props[1].to!uint); + break; + case 'd': + refresh = dur!"days"(props[1].to!uint); + break; + default: + assert(false, "should not get here"); + } + } + +} + +RSSFeedList processFeeds(ParseTree pt) @trusted +{ + RSSFeed[] feeds; + + foreach(ref conf; pt.children) { + foreach(ref feed; conf.children) { + feeds ~= RSSFeed(feed.matches + .filter!((immutable s) => s != "\n" && s != " ") + .array + ); + } + } + if(feeds.empty) return RSSFeedList(InvalidFeeds("No feeds found")); + else return RSSFeedList(feeds); +} + diff --git a/source/cartastraccia/endpoint.d b/source/cartastraccia/endpoint.d index 16e2a18..4b6f46d 100644 --- a/source/cartastraccia/endpoint.d +++ b/source/cartastraccia/endpoint.d @@ -1,5 +1,6 @@ module cartastraccia.endpoint; +import cartastraccia.config; import cartastraccia.actor; import vibe.core.log;