import docopt, os, nre, sequtils, strutils, times, timeutils type ParseState = enum BeforeHeading, ReadingPlans, AfterPlans type PlanItem* = tuple[time: TimeInfo, note: string] proc parseDailyPlan(filename: string): seq[PlanItem] = var planItems: seq[PlanItem] = @[] var parseState = BeforeHeading let planItemRe = re"\s*(\d{4})\s+(.*)" let timeFmt = "HHmm" for line in lines filename: case parseState of BeforeHeading: if line.strip.startsWith("# Timeline"): parseState = ReadingPlans of ReadingPlans: let match = line.find(planItemRe) if match.isSome(): planItems.add(( time: parse(match.get().captures[0], timeFmt), note: match.get().captures[1])) else: parseState = AfterPlans of AfterPlans: break else: break return planItems when isMainModule: let doc = """ Usage: daily_notifier [options] Options: -d --plan-directory Directory to search for plan files. -f --plan-date-format Date pattern for identifying plan files. This is used in conjunction with plan directory to idenfity files that should be parsed as plan files. -c --config Use as the source of configuration for daily-notification. -h --help Print this usage information. """ let args = docopt(doc, version = "daily_notifier 0.1.0") if args["--help"]: echo doc quit() # Find and parse the .dailynotificationrc file let rcLocations = @[ if args["--config"]: $args[""] else:"", ".dailynotificationrc", $getEnv("DAILY_NOTIFICATION_RC"), $getEnv("HOME") & "/.dailynotificationrc"] var ptkrcFilename: string = foldl(rcLocations, if len(a) > 0: a elif existsFile(b): b else: "") # Determine our plan directory and file template # Start our daemon process (if needed) # exit