Skip to content

Commit

Permalink
convert to data app
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Jun 26, 2024
1 parent e5d869d commit e2998b2
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 122 deletions.
2 changes: 1 addition & 1 deletion frameos/frameos.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ before build:

task test, "Run tests":
exec "testament pattern './src/**/tests/*.nim' --lineTrace:on"
exec "testament pattern './src/apps/**/tests/*.nim' --lineTrace:on"
exec "testament pattern './src/apps/**/**/tests/*.nim' --lineTrace:on"
61 changes: 61 additions & 0 deletions frameos/src/apps/data/ical/app.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import pixie
import times
import options
import json
import strformat
import strutils
import httpclient
import frameos/apps
import frameos/types
import chrono

import ./ical

type
AppConfig* = object
ical*: string
exportFrom*: string
exportUntil*: string
exportCount*: int

App* = ref object of AppRoot
appConfig*: AppConfig

proc get*(self: App, context: ExecutionContext): JsonNode =
result = %*[]
if self.appConfig.iCal.startsWith("http"):
self.logError "Pass in iCal data as a string, not a URL."
return
if self.appConfig.iCal == "":
self.logError "No iCal data provided."
return

var client = newHttpClient(timeout = 60000)
var parsedEvents: seq[VEvent]
try:
parsedEvents = parseICalendar(self.appConfig.ical)
except CatchableError as e:
self.logError "Error parsing iCal: " & $e.msg
return
finally:
client.close()

let timezone = now().timezone()
let exportFrom = (if self.appConfig.exportFrom != "": parse(self.appConfig.exportFrom, "yyyy-MM-dd",
timezone) else: now()).toTime().toUnixFloat().Timestamp
var exportUntil = if self.appConfig.exportUntil != "": parse(self.appConfig.exportUntil, "yyyy-MM-dd",
timezone).toTime().toUnixFloat().Timestamp else: 0.Timestamp
let matchedEvents = getEvents(parsedEvents, exportFrom, exportUntil, self.appConfig.exportCount)
var eventsReply: JsonNode = %[]
for (time, event) in matchedEvents:
let jsonEvent = %*{
"summary": event.summary,
"startTime": fromUnixFloat(time.float).format("yyyy-MM-dd'T'HH:mm:ss"),
"endTime": fromUnixFloat(time.float + (event.endTime.float - event.startTime.float)).format(
"yyyy-MM-dd'T'HH:mm:ss"),
"location": event.location,
"description": event.description,
}
eventsReply.add(jsonEvent)
self.log(%*{"event": &"reply", "events": len(eventsReply), "inRange": len(eventsReply)})
return eventsReply
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
{
"name": "iCal to State",
"description": "Read iCal URLs",
"name": "iCal to JSON",
"description": "Convert an iCal file into a JSON event list",
"category": "utils",
"version": "1.0.0",
"fields": [
{
"name": "url",
"name": "ical",
"type": "string",
"value": "https://calendar.google.com/calendar/ical/0hfd6vcbncn6p5hn1t4d2b2k4s%40group.calendar.google.com/public/basic.ics",
"required": true,
"label": "Calendar URL",
"placeholder": ""
},
{
"name": "cacheSeconds",
"type": "float",
"value": "60",
"required": false,
"label": "Seconds between calendar refreshes",
"placeholder": "Default: 60. Use 0 to download every time."
"label": "iCal file contents"
},
{
"name": "exportFrom",
Expand All @@ -43,13 +33,16 @@
"placeholder": "1000",
"required": false,
"label": "Maximum number of events to export"
},
}
],
"output": [
{
"name": "stateKey",
"type": "string",
"value": "events",
"required": true,
"label": "State key to store events in"
"name": "events",
"type": "json"
}
]
],
"cache": {
"enabled": true,
"inputEnabled": true
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
100 changes: 0 additions & 100 deletions frameos/src/apps/ical/app.nim

This file was deleted.

0 comments on commit e2998b2

Please sign in to comment.