From b36689f30341c3219e4e3d6bf1199a5b5e7ee844 Mon Sep 17 00:00:00 2001 From: rek2 Date: Sat, 18 Sep 2021 02:02:18 +0200 Subject: [PATCH] separared config and parse of secrects into their own functions wrote some minor readme --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ main.go | 35 ++++++++++++++++++++++------------- 2 files changed, 60 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c6bb47a..fb2d6b6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,40 @@ to be finished you need to create a config.ini + + -- +# create config file: +go into mastodon in your account settings and create a new app under development +get the: +- clientID and the clientSecret + +you will need the user/pass for the account the bot will post the videos +also the servername of the mastodon instance and +the feed URL for odysee or peertube + +save your mastodon client secrect and login password in gopass or pass +``` +pass insert gotootramdonvideo/clientsecret +pass insert gotootramdonvideo/clientid +pass insert gotootramdonvideo/password +``` + +it will show on gopass ls like: +``` +├── gotootramdonvideo/ +│ ├── clientid +│ ├── clientsecret +│ └── password +``` + +config.ini will be something line: +``` +[mastodon] +server = https://hispagatos.space +client_id = `gopass show -o -f gotootramdonvideo/clientid` +client_secret = `gopass show -o -f gotootramdonvideo/clientsecret` +username = hackersespanol@gmail.com +password = `gopass show -o -f gotootramdonvideo/password` + +[odysee] +feed_url = https://odysee.com/$/rss/@Hackernol:7 +``` diff --git a/main.go b/main.go index c60d505..49bf00d 100644 --- a/main.go +++ b/main.go @@ -24,18 +24,7 @@ type theFeed struct { func main() { - cfg, err := ini.Load("config.ini") - if err != nil { - fmt.Printf("Fail to read file: %v", err) - os.Exit(1) - } - - server := cfg.Section("mastodon").Key("server").String() - clientId := cfg.Section("mastodon").Key("client_id").String() - clientSecret := cfg.Section("mastodon").Key("client_secret").String() - username := cfg.Section("mastodon").Key("username").String() - password := cfg.Section("mastodon").Key("password").String() - feedURL := cfg.Section("odysee").Key("feed_url").String() + server, clientId, clientSecret, username, password, feedURL := readConfig() c := mastodon.NewClient(&mastodon.Config{ Server: server, @@ -45,7 +34,7 @@ func main() { error := c.Authenticate(context.Background(), username, password) if error != nil { - log.Fatal(err) + log.Fatal(error) } feeds := parseFeed(feedURL) @@ -109,3 +98,23 @@ func parseCredentials(command string) (string, error) { return sec, nil } + +func readConfig() (string, string, string, string, string, string) { + cfg, err := ini.Load("config.ini") + if err != nil { + fmt.Printf("Fail to read file: %v", err) + os.Exit(1) + } + + 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()) + username := cfg.Section("mastodon").Key("username").String() + password, err := parseCredentials(cfg.Section("mastodon").Key("password").String()) + feedURL := cfg.Section("odysee").Key("feed_url").String() + if err != nil { + log.Fatal(err) + } + + return server, clientId, clientSecret, username, password, feedURL +} -- 2.45.2