-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1285c1
commit 7972ca7
Showing
3 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import frameos/apps | ||
import frameos/types | ||
import json | ||
import strformat | ||
import strutils | ||
import chrono | ||
import times | ||
import pixie | ||
|
||
type | ||
AppConfig* = object | ||
events*: JsonNode | ||
baseFontSize*: int | ||
titleFontSize*: int | ||
textColor*: Color | ||
timeColor*: Color | ||
titleColor*: Color | ||
|
||
App* = ref object of AppRoot | ||
appConfig*: AppConfig | ||
|
||
const titleFormat = "{weekday}, {month/n} {day}" | ||
|
||
proc get*(self: App, context: ExecutionContext): string = | ||
let title = &"^({self.appConfig.titleFontSize},{self.appConfig.titleColor.toHtmlHex()})" | ||
let normal = &"^({self.appConfig.baseFontSize},{self.appConfig.textColor.toHtmlHex()})" | ||
let time = &"^({self.appConfig.baseFontSize},{self.appConfig.timeColor.toHtmlHex()})" | ||
let events = self.appConfig.events | ||
let todayTs = epochTime().Timestamp | ||
let today = format(todayTs, titleFormat) | ||
|
||
proc h1(text: string): string = &"{title}{text}\n{normal}\n" | ||
proc formatDay(day: string): string = format(parseTs("{year/4}-{month/2}-{day/2}", day), titleFormat) | ||
|
||
var currentDay = format(todayTs, "{year/4}-{month/2}-{day/2}") | ||
|
||
result = h1(today) | ||
|
||
if events == nil or events.kind != JArray or events.len == 0: | ||
result &= &"No events found" | ||
return | ||
|
||
var hasAny = false | ||
for obj in events.items(): | ||
let summary = obj{"summary"}.getStr() | ||
let startDay = obj{"startTime"}.getStr() | ||
let endDay = obj{"endTime"}.getStr() | ||
let withTime = "T" in startDay | ||
let startDate = startDay.split("T")[0] | ||
|
||
if startDate > currentDay: | ||
if not hasAny: | ||
result &= "No events today\n" | ||
|
||
result &= "\n" & h1(formatDay(startDate)) | ||
currentDay = startDate | ||
|
||
hasAny = true | ||
|
||
if withTime: | ||
let startTime = if "T" in startDay: startDay.split("T")[1][0 .. 4] else: "" | ||
let endTime = if "T" in endDay: endDay.split("T")[1][0 .. 4] else: "" | ||
result &= &"{time}{startTime} - {endTime} {normal}{summary}\n" | ||
else: | ||
if startDay == currentDay and endDay == currentDay: | ||
result &= &"{time}All day {normal}{summary}\n" | ||
else: | ||
result &= &"{time}Until {formatDay(endDay)} {normal}{summary}\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"name": "Events to Agenda", | ||
"description": "Convert events to an basic-caret formatted agenda string", | ||
"category": "data", | ||
"version": "1.0.0", | ||
"fields": [ | ||
{ | ||
"name": "events", | ||
"type": "json", | ||
"required": true, | ||
"label": "Events" | ||
}, | ||
{ | ||
"name": "baseFontSize", | ||
"type": "integer", | ||
"value": "24", | ||
"required": true, | ||
"label": "Base font size" | ||
}, | ||
{ | ||
"name": "titleFontSize", | ||
"type": "integer", | ||
"value": "48", | ||
"required": true, | ||
"label": "Title font size" | ||
}, | ||
{ | ||
"name": "titleColor", | ||
"type": "color", | ||
"value": "#FFFFFF", | ||
"required": true, | ||
"label": "Day title color" | ||
}, | ||
{ | ||
"name": "textColor", | ||
"type": "color", | ||
"value": "#FFFFFF", | ||
"required": true, | ||
"label": "Base text color" | ||
}, | ||
{ | ||
"name": "timeColor", | ||
"type": "color", | ||
"value": "#FF0000", | ||
"required": true, | ||
"label": "Time color" | ||
} | ||
], | ||
"output": [ | ||
{ | ||
"name": "result", | ||
"type": "string" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters