update keys

This commit is contained in:
Владимир Фёдоров 2022-04-25 00:46:48 +07:00
parent cc240dc13d
commit c2b383b5cc
2 changed files with 44 additions and 3 deletions

3
.gitignore vendored
View File

@ -2,3 +2,6 @@
*.json
/bin
!/config/new_year_config.json
token.txt
token_weather.txt

44
main.go
View File

@ -2,6 +2,8 @@ package main
import (
"errors"
"fmt"
"io/ioutil"
"log"
"math/rand"
"os"
@ -20,21 +22,37 @@ import (
type Opts struct {
Token string `short:"t" long:"token" description:"Telegram api token"`
Key string `short:"k" long:"key" description:"Yandex weather API key"`
Name string `short:"n" long:"name" description:"Telegram bot name" default:"@student_verochka_bot"`
Key string `short:"k" long:"key" description:"Yandex weather API key"`
}
var sendMessage = false
var opts Opts
func readToken() (string, error) {
b, err := ioutil.ReadFile("token.txt")
if err != nil {
return "", err
}
str := string(b)
return str, nil
}
func readWeatherToken() (string, error) {
b, err := ioutil.ReadFile("token_weather.txt")
if err != nil {
return "", err
}
str := string(b)
return str, nil
}
func main() {
run()
}
func run() {
rand.Seed(time.Now().UnixNano())
p := flags.NewParser(&opts, flags.PrintErrors|flags.PassDoubleDash|flags.HelpFlag)
p.SubcommandsOptional = true
if _, err := p.Parse(); err != nil {
@ -44,6 +62,26 @@ func run() {
os.Exit(2)
}
if opts.Token == "" {
token, err := readToken()
if err != nil {
panic(err)
}
opts.Token = strings.ReplaceAll(token, "\n", "")
}
fmt.Println(opts.Token)
if opts.Key == "" {
token, err := readWeatherToken()
if err != nil {
panic(err)
}
opts.Key = strings.ReplaceAll(token, "\n", "")
}
fmt.Println(opts.Key)
rand.Seed(time.Now().UnixNano())
imageService, err := new_year_service.NewNewYearService()
if err != nil {
log.Panicln(err)