From 192c0ad00761b4fae0e08dbb10c819c647eeda87 Mon Sep 17 00:00:00 2001 From: Andrew W Date: Fri, 23 Sep 2022 00:24:46 -0500 Subject: [PATCH] added more queries, made queries random --- main.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index ce93489..c0557e0 100644 --- a/main.go +++ b/main.go @@ -38,31 +38,37 @@ func architectureBot() { password string } + rand.Seed(time.Now().UnixNano()) + + queryArr := viper.GetStringSlice("queries") + queryArrLen := len(queryArr) + queryIndex := rand.Int31n(int32(queryArrLen)) + query := queryArr[queryIndex] + cli := pexels.NewClient(viper.GetString("PexelsAPIKey")) ps, err := cli.PhotoService.Search(context.Background(), &pexels.PhotoParams{ - Query: "neoclassical architecture", + Query: query, PerPage: 80, }) if err != nil { log.Fatal(err) } - ps.Page = rand.Intn(79) - rand.Seed(time.Now().UnixNano()) + ps.Page = rand.Intn(100) photoIndex := rand.Intn(79) photo := ps.Photos[photoIndex] // fmt.Println("Source Medium URL:", ps.Photos[0].Src.Medium) photoURL := photo.Src.Original mime := strings.Split(photoURL, "/") - ext := mime[len(mime)-1] - fileName := "images/" + fmt.Sprint(photo.ID) + "." + fmt.Sprint(ext) + name := mime[len(mime)-1] + fileName := "images/" + fmt.Sprint(name) os.Mkdir("images", 0700) err = downloadFile(photoURL, fileName) if err != nil { log.Fatal(err) } - fmt.Println(ps.TotalResults, "Original SRC URL: ", photoURL) + // fmt.Println("Original SRC URL: ", photoURL) post := "Taken from " + photo.URL + "\n#neoclassical"