GImages/api.py

20 lines
529 B
Python
Raw Normal View History

2024-11-04 17:11:13 +03:00
from google_images_search import GoogleImagesSearch
import creds
2024-11-04 18:28:47 +03:00
from creds import gimgsettings
2024-11-04 17:11:13 +03:00
gis = GoogleImagesSearch(creds.api, creds.cx)
def get_img(query, count):
2024-11-04 17:11:13 +03:00
gis.search(search_params= {
'q': query,
2024-11-04 18:28:47 +03:00
'safe': gimgsettings['safesearch'],
'num': count,
2024-11-04 17:11:13 +03:00
})
if count == 1:
return gis.results()[0].url
else:
results = ""
response = gis.results()
for result in response:
results += f"{result.url}\n"
return results