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 elif cfg.json.hasKey(jsonKey): return cfg.json[jsonKey].getStr
else: return default else: return default
const VERSION = "0.2.0" const VERSION = "0.2.2"
const timeFmt = "HH:mm" const timeFmt = "HH:mm"
var args: Table[string, Value] var args: Table[string, Value]
var cfg: DPConfig var cfg: DPConfig
let appName = getAppFilename()
let soundFile = appName[0..(appName.len-15)] & "sounds/notify1.ogg"
proc parseDailyPlan(filename: string): seq[PlanItem] = proc parseDailyPlan(filename: string): seq[PlanItem] =
result = @[] result = @[]
if not existsFile(filename): return
var parseState = BeforeHeading var parseState = BeforeHeading
let planItemRe = re"\s*(\d{4})\s+(.*)" let planItemRe = re"\s*(\d{4})\s+(.*)"
const timeFmt = "HHmm" const timeFmt = "HHmm"
@ -66,6 +66,8 @@ proc notifyDailyPlanItem(item: PlanItem): void =
of "linux": of "linux":
discard execShellCmd("notify-send 'Daily Notifier v" & VERSION & "' '" & item.note & "'") discard execShellCmd("notify-send 'Daily Notifier v" & VERSION & "' '" & item.note & "'")
discard execShellCmd("paplay \"" & soundFile & "\"")
echo "paplay \"" & soundFile & "\""
else: quit("Unsupported host OS: '" & hostOS & "'.") else: quit("Unsupported host OS: '" & hostOS & "'.")
@ -103,19 +105,31 @@ proc mainLoop(args: Table[string, Value]): void =
loadConfig(0) loadConfig(0)
signal(SIGHUP, loadConfig) signal(SIGHUP, loadConfig)
var curDay: TimeInfo = getLocalTime(fromSeconds(0)) var curDay: TimeInfo = getLocalTime(fromSeconds(0))
var todaysFile = "nofile"
var lastModTime = fromSeconds(0)
var todaysItems: seq[PlanItem] = @[] var todaysItems: seq[PlanItem] = @[]
while true: while true:
# Check the date # Check the date
let now = getLocalTime(getTime()) 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: if today != curDay:
curDay = today curDay = today
let todaysPlanFile = todaysFile = cfg.planDir & "/" & today.format(cfg.dateFmt) & "-plan.md"
cfg.planDir & "/" & today.format(cfg.dateFmt) & "-plan.md" todaysItems = @[]
todaysItems = parseDailyPlan(todaysPlanFile) 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. # Check to see if any items are happening soon.
let cutoff = now + seconds(cfg.notificationSecs) let cutoff = now + seconds(cfg.notificationSecs)

View File

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