added more queries, made queries random
This commit is contained in:
		
							
								
								
									
										18
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								main.go
									
									
									
									
									
								
							| @@ -38,31 +38,37 @@ func architectureBot() { | |||||||
| 		password     string | 		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")) | 	cli := pexels.NewClient(viper.GetString("PexelsAPIKey")) | ||||||
| 	ps, err := cli.PhotoService.Search(context.Background(), &pexels.PhotoParams{ | 	ps, err := cli.PhotoService.Search(context.Background(), &pexels.PhotoParams{ | ||||||
| 		Query:   "neoclassical architecture", | 		Query:   query, | ||||||
| 		PerPage: 80, | 		PerPage: 80, | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Fatal(err) | 		log.Fatal(err) | ||||||
| 	} | 	} | ||||||
| 	ps.Page = rand.Intn(79) | 	ps.Page = rand.Intn(100) | ||||||
| 	rand.Seed(time.Now().UnixNano()) |  | ||||||
| 	photoIndex := rand.Intn(79) | 	photoIndex := rand.Intn(79) | ||||||
| 	photo := ps.Photos[photoIndex] | 	photo := ps.Photos[photoIndex] | ||||||
|  |  | ||||||
| 	// fmt.Println("Source Medium URL:", ps.Photos[0].Src.Medium) | 	// fmt.Println("Source Medium URL:", ps.Photos[0].Src.Medium) | ||||||
| 	photoURL := photo.Src.Original | 	photoURL := photo.Src.Original | ||||||
| 	mime := strings.Split(photoURL, "/") | 	mime := strings.Split(photoURL, "/") | ||||||
| 	ext := mime[len(mime)-1] | 	name := mime[len(mime)-1] | ||||||
| 	fileName := "images/" + fmt.Sprint(photo.ID) + "." + fmt.Sprint(ext) | 	fileName := "images/" + fmt.Sprint(name) | ||||||
| 	os.Mkdir("images", 0700) | 	os.Mkdir("images", 0700) | ||||||
| 	err = downloadFile(photoURL, fileName) | 	err = downloadFile(photoURL, fileName) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Fatal(err) | 		log.Fatal(err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	fmt.Println(ps.TotalResults, "Original SRC URL: ", photoURL) | 	// fmt.Println("Original SRC URL: ", photoURL) | ||||||
|  |  | ||||||
| 	post := "Taken from " + photo.URL + "\n#neoclassical" | 	post := "Taken from " + photo.URL + "\n#neoclassical" | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Andrew W
					Andrew W