~rek2/goTootRamdonVideo

b36689f30341c3219e4e3d6bf1199a5b5e7ee844 — rek2 2 years ago 66c5dcf
separared config and parse of secrects into their own functions wrote some minor readme
2 files changed, 60 insertions(+), 13 deletions(-)

M README.md
M main.go
M README.md => README.md +38 -0
@@ 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 
```

M main.go => main.go +22 -13
@@ 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
}