GImages/api.py

19 lines
479 B
Python
Raw Normal View History

2024-11-04 17:11:13 +03:00
from google_images_search import GoogleImagesSearch
import creds
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,
'safe': 'active',
'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