-
-
Notifications
You must be signed in to change notification settings - Fork 256
Add .quote daily and .quote random command to retrieve quotes from zenquotes.io api #1707
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
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e5d1672
feat: Add .quote and .daily_quote command to retrieve a random quote …
mhaxanali d5708a7
run pre-commit hooks
mhaxanali 6b354d0
Implement suggested changes except daily quote caching.
mhaxanali e22bf2a
run pre-commit hooks
mhaxanali 6b873c2
Add attribution hyperlink
mhaxanali b717bfa
Implement caching for daily quote to minimize API requests.
mhaxanali 5adb196
fix typos
mhaxanali 4131e40
fix typos
mhaxanali 686014b
Implement suggested changes
mhaxanali 40a9445
Revert uv.lock since aiohttp is unpinned
mhaxanali f7a7b13
escape special characters before author's names
mhaxanali 84b497f
run pre-commit hooks
mhaxanali 60303e6
remove \ because escaping the — was not needed
mhaxanali c074c94
Merge branch 'main' into feature/quote
mhaxanali 875b5e8
Merge branch 'main' into feature/quote
jb3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import aiohttp | ||
|
|
||
|
|
||
| async def random_quote() -> str: | ||
| """Retrieves a random quote from zenquotes.io api.""" | ||
| url = "https://zenquotes.io/api/random" | ||
mhaxanali marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| async with aiohttp.ClientSession() as session, session.get(url) as response: | ||
mhaxanali marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if response.status != 200: | ||
mhaxanali marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return "Error: Data not Retrieved" | ||
| data = await response.json() | ||
|
|
||
| quote = f"{data[0]['q']}\n-{data[0]['a']}" | ||
| return quote | ||
|
|
||
|
|
||
| async def daily_quote() -> str: | ||
| """Retrieves the daily quote from zenquotes.io api.""" | ||
| url = "https://zenquotes.io/api/today" | ||
mhaxanali marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| async with aiohttp.ClientSession() as session, session.get(url) as response: | ||
| if response.status != 200: | ||
| return "Error: Data not Retrieved" | ||
| data = await response.json() | ||
|
|
||
| quote = f"{data[0]['q']}\n-{data[0]['a']}" | ||
| return quote | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.