added more queries, made queries random

master
Andrew W 2 years ago
parent 4d29ab3b30
commit 192c0ad007

@ -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"

Loading…
Cancel
Save