forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgiphy.py
19 lines (14 loc) · 575 Bytes
/
giphy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python3
importrequests
giphy_api_key="YOUR API KEY"
# Can be fetched from https://developers.giphy.com/dashboard/
defget_gifs(query: str, api_key: str=giphy_api_key) ->list:
"""
Get a list of URLs of GIFs based on a given query..
"""
formatted_query="+".join(query.split())
url=f"https://api.giphy.com/v1/gifs/search?q={formatted_query}&api_key={api_key}"
gifs=requests.get(url, timeout=10).json()["data"]
return [gif["url"] forgifingifs]
if__name__=="__main__":
print("\n".join(get_gifs("space ship")))