1
0
mirror of https://git.keinpfusch.net/loweel/zorg synced 2024-12-20 00:52:50 +01:00
zorg/env.go

71 lines
1.4 KiB
Go
Raw Permalink Normal View History

2020-10-08 21:33:26 +02:00
package main
import (
2023-07-15 02:04:50 +02:00
"context"
2020-10-08 21:33:26 +02:00
"encoding/json"
2023-07-15 02:04:50 +02:00
"fmt"
2020-10-08 21:33:26 +02:00
"io/ioutil"
"log"
"os"
"time"
2023-07-15 02:04:50 +02:00
"github.com/mattn/go-mastodon"
2020-10-08 21:33:26 +02:00
)
// ZorgConfig is the configuration of Zorg.
var ZorgConfig struct {
ZorgServer string `json:"ZorgServer"`
ZorgClientID string `json:"ZorgClientID"`
ZorgClientSecret string `json:"ZorgClientSecret"`
ZorgUname string `json:"ZorgUname"`
ZorgPass string `json:"ZorgPass"`
ZorgInterval int `json:"ZorgInterval"`
}
// Zint is the poll time
var Zint time.Duration
func init() {
//reading json file
file, err := ioutil.ReadFile("zorg.conf")
if err != nil {
log.Println("Cannot open config file", err.Error())
os.Exit(1)
}
err = json.Unmarshal([]byte(file), &ZorgConfig)
if err != nil {
log.Println("Cannot marshal json: ", err.Error())
os.Exit(1)
}
Zint = time.Duration(time.Duration(ZorgConfig.ZorgInterval) * time.Second)
2023-07-15 02:04:50 +02:00
ZorgCreateToken()
2020-10-08 21:33:26 +02:00
log.Println("Inizialized ZORG")
}
2023-07-15 02:04:50 +02:00
func ZorgCreateToken() {
app, err := mastodon.RegisterApp(context.Background(), &mastodon.AppConfig{
Server: ZorgConfig.ZorgServer,
ClientName: "Zorg",
Scopes: "read write follow",
Website: ZorgConfig.ZorgServer,
})
if err != nil {
log.Fatal(err)
}
ZorgConfig.ZorgClientID = app.ClientID
ZorgConfig.ZorgClientSecret = app.ClientSecret
fmt.Printf("Zorg new client-id : %s\n", ZorgConfig.ZorgClientID)
fmt.Printf("Zorg new client-secret: %s\n", ZorgConfig.ZorgClientSecret)
}