Spaces:
Running
Running
File size: 386 Bytes
dacef8c 19ac67f dacef8c 19ac67f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import requests
from random import choice
from env import GOOGLE_API_KEY, CX
def search_img(term):
_ret = requests.get(
url=f"https://www.googleapis.com/customsearch/v1?key={GOOGLE_API_KEY}&cx={CX}&q={term}&searchType=image&fields=items(link)"
)
try:
return choice(_ret.json()['items'][:10])['link']
except:
print(_ret.json())
return ""
|