From c2b383b5ccf2a3396ac28fe85428d6a000987449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=20=D0=A4?= =?UTF-8?q?=D0=B5=D0=B4=D0=BE=D1=80=D0=BE=D0=B2?= Date: Mon, 25 Apr 2022 00:46:48 +0700 Subject: [PATCH] update keys --- .gitignore | 3 +++ main.go | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 78d7f4e..15d52f4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ *.json /bin !/config/new_year_config.json + +token.txt +token_weather.txt diff --git a/main.go b/main.go index 5b24fd6..3a885ea 100644 --- a/main.go +++ b/main.go @@ -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)