From bb4c5c4333b8f80fb4abaa25437f23e91e0d61ad Mon Sep 17 00:00:00 2001 From: rek2 Date: Sat, 18 Sep 2021 04:42:48 +0200 Subject: [PATCH] added interval int to config and main --- config.ini | 3 +++ main.go | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/config.ini b/config.ini index 21597f8..a309b64 100644 --- a/config.ini +++ b/config.ini @@ -1,3 +1,6 @@ +[general] +interval = 60 + [mastodon] server = https://hispagatos.space client_id = `gopass show -o -f gotootramdonvideo/clientid` diff --git a/main.go b/main.go index 4ef356a..e60d68b 100644 --- a/main.go +++ b/main.go @@ -31,7 +31,7 @@ type theFeed struct { func main() { // get config parameters - server, clientId, clientSecret, username, password, feedURL := readConfig() + interval, server, clientId, clientSecret, username, password, feedURL := readConfig() // daemonize cntxt := &daemon.Context{ @@ -69,7 +69,7 @@ func main() { // run every x times and blocks the program to keep it running cron := gocron.NewScheduler(time.UTC) - cron.Every(5).Minutes().Do(mastodonTask, c, feedURL) + cron.Every(interval).Minutes().Do(mastodonTask, c, feedURL) cron.StartBlocking() } @@ -152,7 +152,7 @@ func parseCredentials(command string) (string, error) { return sec, nil } -func readConfig() (string, string, string, string, string, string) { +func readConfig() (int, string, string, string, string, string, string) { // read config.ini // get all parameters @@ -163,6 +163,7 @@ func readConfig() (string, string, string, string, string, string) { os.Exit(1) } + interval := cfg.Section("general").Key("interval").MustInt() server := cfg.Section("mastodon").Key("server").String() clientId, err := parseCredentials(cfg.Section("mastodon").Key("client_id").String()) clientSecret, err := parseCredentials(cfg.Section("mastodon").Key("client_secret").String()) @@ -173,5 +174,5 @@ func readConfig() (string, string, string, string, string, string) { log.Fatal(err) } - return server, clientId, clientSecret, username, password, feedURL + return interval, server, clientId, clientSecret, username, password, feedURL } -- 2.45.2