Skip to content

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

Merged
merged 10 commits into from
Oct 18, 2021
Merged

Added giphy.py to fetch gifs on a given topic #5378

merged 10 commits into from
Oct 18, 2021

Conversation

JDeepD
Copy link
Contributor

@JDeepD JDeepD commented Oct 17, 2021

Describe your change:

Added giphy.py script which can fetch a GIF from giphy on any given topic

  • Add an algorithm script?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@JDeepD JDeepD requested a review from cclauss as a code owner October 17, 2021 15:13
@ghost ghost added awaiting reviews This PR is ready to be reviewed require tests Tests [doctest/unittest/pytest] are required labels Oct 17, 2021
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

# Can be fetched from https://developers.giphy.com/dashboard/


def getgif(query: str) -> str:
Copy link

Choose a reason for hiding this comment

The 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 web_programming/giphy.py, please provide doctest for the function getgif

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@ghost ghost added the tests are failing Do not merge until tests pass label Oct 17, 2021
[*]Added doctest
[*]Formatted with black
Total urls received: 50
https://giphy.com/gifs/startrekfleetcommand-BPVIRni1Z70QO2nJMX
"""
qu: str = '+'.join(query.split(" "))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
qu: str = '+'.join(query.split(" "))
query = '+'.join(query.split(" "))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍🏻

@ghost ghost removed the require tests Tests [doctest/unittest/pytest] are required label Oct 17, 2021
@ghost ghost added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Oct 17, 2021
@ghost ghost added awaiting reviews This PR is ready to be reviewed and removed awaiting changes A maintainer has requested changes to this PR labels Oct 18, 2021
@JDeepD
Copy link
Contributor Author

JDeepD commented Oct 18, 2021

@cclauss Made the changes.

Comment on lines 18 to 21
data = requests.get(url).json()
url_data = [i["url"] for i in data["data"]]

return url_data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data = requests.get(url).json()
url_data = [i["url"] for i in data["data"]]
return url_data
return = [gif["url"] for gif in requests.get(url).json()["data"]]

@ghost ghost added the require tests Tests [doctest/unittest/pytest] are required label Oct 18, 2021
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for doing this.

@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Oct 18, 2021
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

# Can be fetched from https://developers.giphy.com/dashboard/


def get_gifs(query: str, api_key: str = giphy_api_key) -> list:
Copy link

Choose a reason for hiding this comment

The 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 web_programming/giphy.py, please provide doctest for the function get_gifs

@ghost ghost added the awaiting reviews This PR is ready to be reviewed label Oct 18, 2021
@JDeepD
Copy link
Contributor Author

JDeepD commented Oct 18, 2021

LGTM. Thanks for doing this.

Thanks. Just 10 mins. I should probably add some try..except statements before requesting so that errors are caught.

@ghost ghost removed the tests are failing Do not merge until tests pass label Oct 18, 2021
@cclauss cclauss merged commit 0935ab0 into TheAlgorithms:master Oct 18, 2021
@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Oct 18, 2021
@cclauss
Copy link
Member

cclauss commented Oct 18, 2021

It is OK. Not all errors need to be caught. This is relatively simple code so the errors should only be for:

  1. No API key provided.
  2. Internet connection to GIPHY is down.

@JDeepD
Copy link
Contributor Author

JDeepD commented Oct 18, 2021

Ohk. Thanks

@JDeepD JDeepD deleted the dev branch October 18, 2021 07:30
shermanhui pushed a commit to shermanhui/Python that referenced this pull request Oct 22, 2021
* Added giphy.py to fetch gifs on a given topic

* Modified code
[*]Added doctest
[*]Formatted with black

* Minor change

* Minor refactoring to avoid name clash

* Made necessary changes as per review

* Update web_programming/giphy.py

Co-authored-by: Christian Clauss <[email protected]>

* Apply suggestions from code review

* Final cleanup

* Placate psf/black

Co-authored-by: Christian Clauss <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
require tests Tests [doctest/unittest/pytest] are required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants