3 Commits
0.2.0 ... 0.2.2

2 changed files with 23 additions and 9 deletions

View File

@ -23,18 +23,18 @@ proc getVal(cfg: CombinedConfig, key, default: string): string =
elif cfg.json.hasKey(jsonKey): return cfg.json[jsonKey].getStr
else: return default
const VERSION = "0.2.0"
const VERSION = "0.2.2"
const timeFmt = "HH:mm"
var args: Table[string, Value]
var cfg: DPConfig
let appName = getAppFilename()
let soundFile = appName[0..(appName.len-15)] & "sounds/notify1.ogg"
proc parseDailyPlan(filename: string): seq[PlanItem] =
result = @[]
if not existsFile(filename): return
var parseState = BeforeHeading
let planItemRe = re"\s*(\d{4})\s+(.*)"
const timeFmt = "HHmm"
@ -66,6 +66,8 @@ proc notifyDailyPlanItem(item: PlanItem): void =
of "linux":
discard execShellCmd("notify-send 'Daily Notifier v" & VERSION & "' '" & item.note & "'")
discard execShellCmd("paplay \"" & soundFile & "\"")
echo "paplay \"" & soundFile & "\""
else: quit("Unsupported host OS: '" & hostOS & "'.")
@ -103,19 +105,31 @@ proc mainLoop(args: Table[string, Value]): void =
loadConfig(0)
signal(SIGHUP, loadConfig)
var curDay: TimeInfo = getLocalTime(fromSeconds(0))
var todaysFile = "nofile"
var lastModTime = fromSeconds(0)
var todaysItems: seq[PlanItem] = @[]
while true:
# Check the date
let now = getLocalTime(getTime())
var today = startOfDay(now)
let today = startOfDay(now)
# Load today's plan items
# If we need to change day, look for a new file.
if today != curDay:
curDay = today
let todaysPlanFile =
cfg.planDir & "/" & today.format(cfg.dateFmt) & "-plan.md"
todaysItems = parseDailyPlan(todaysPlanFile)
todaysFile = cfg.planDir & "/" & today.format(cfg.dateFmt) & "-plan.md"
todaysItems = @[]
lastModTime = fromSeconds(0)
# Check for our plan file.
if fileExists(todaysFile):
let fileModTime = getLastModificationTime(todaysFile)
# Check if the file has been modified or we have no itmes
if fileModTime > lastModTime or todaysItems.len == 0:
lastModTime = fileModTime
todaysItems = parseDailyPlan(todaysFile)
# Check to see if any items are happening soon.
let cutoff = now + seconds(cfg.notificationSecs)

View File

@ -1,6 +1,6 @@
# Package
version = "0.2.0"
version = "0.2.2"
author = "Jonathan Bernard"
description = "Little programs that reads my daily plan and notifies me of upcoming events."
license = "MIT"