From 6eadef654f29edfe4dfbf470212b1da5a28b0f3f Mon Sep 17 00:00:00 2001 From: Parnic Date: Sun, 3 Dec 2023 19:18:26 -0600 Subject: [PATCH] Add daemonize mode, readme --- .vscode/launch.json | 10 +++++++++- README.md | 17 +++++++++++++++++ main.go | 6 ++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/.vscode/launch.json b/.vscode/launch.json index 608d3c6..a632b3e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,15 @@ "type": "go", "request": "launch", "mode": "auto", - "program": "${fileDirname}" + "program": "${workspaceFolder}/main.go" + }, + { + "name": "Launch daemonized", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}/main.go", + "args": ["-d"] } ] } \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c603c41 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Advent of Code leaderboard tracker for Mattermost + +## Summary + +This is an application designed to be run on some sort of cron-like schedule or on its own with the `-d` argument where it will scan every 15 minutes. It will check the status of an [Advent of Code](https://adventofcode.com) leaderboard and report any diffs to the given Mattermost webhook. + +## Configurables + +The following configurables are supported in either argument ("-arg=val"), environment, or [.env](https://github.com/joho/godotenv) file form: + +Argument | Env var | Description | Default +---- | ---- | ---- | ---- +year | (none) | The event year to scan | "2023" +leaderboard | AOC_LEADERBOARD | The leaderboard ID to read (e.g. 1234567) | "" +session | AOC_SESSION | A valid session ID pulled from your web browser on a logged-in account | "" +webhookURL | AOC_WEBHOOK | The full URL for an incoming webhook to your Mattermost instance (e.g. https://my.mattermost.server/hooks/abcd1234) | "" +d | (none) | Daemonize the application so it refreshes itself every 15 minutes | false diff --git a/main.go b/main.go index 316a1d3..d1fb889 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ var ( leaderboardArg = flag.String("leaderboard", "", "the leaderboard code to check") sessionArg = flag.String("session", "", "session cookie to use to request the leaderboard") webhookURLArg = flag.String("webhookURL", "", "webhook to post updates to") + daemonizeArg = flag.Bool("d", false, "daemonizes the application to run and scan every 15 minutes") ) var ( @@ -220,6 +221,11 @@ func main() { } } + if !*daemonizeArg { + refresh() + return + } + c := cron.New() c.AddFunc("*/15 * * * *", refresh)