-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Added giphy.py to fetch gifs on a given topic #5378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
633327c
6f619cb
e43618a
25c9d3b
2046753
4997f35
157e0f6
c44299c
6dd357a
8eb25e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/python | ||
import random | ||
import json | ||
import requests | ||
JDeepD marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
api_key = "YOUR GIPHY API KEY" | ||
# Can be fetched from https://developers.giphy.com/dashboard/ | ||
|
||
|
||
def getgif(query: str) -> str: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think adding doctest will not be helpful in this scenario because the output(url of gif) is chosen at random. |
||
""" | ||
Get 1 URL of GIF on a given `query` | ||
|
||
>>> getgif("space ship") | ||
Topic: space+ship | ||
Total urls received: 50 | ||
https://giphy.com/gifs/startrekfleetcommand-BPVIRni1Z70QO2nJMX | ||
""" | ||
formatted_query: str = "+".join(query.split(" ")) | ||
print("Topic: ", formatted_query) | ||
url: str = f"http://api.giphy.com/v1/gifs/search?q={formatted_query}&api_key={api_key}" | ||
jsdata = requests.get(url) | ||
data: dict = json.loads(jsdata.content) | ||
JDeepD marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print("Total urls received: ", len(data["data"])) | ||
return data["data"][random.randint(0, 49)]["url"] | ||
|
||
|
||
print(getgif("space ship")) | ||
JDeepD marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.