This repository was archived by the owner on Mar 14, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Team 7 #2
Open
ghost
wants to merge
19
commits into
python-discord:master
Choose a base branch
from
unknown repository
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Team 7 #2
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
05f2181
Test commit
mushfikurr 9b48937
Merge pull request #1 from discord-python/master
ae13f3b
Merge pull request #2 from discord-python/master
3f8e491
Basic search snake command
mushfikurr 9ff833d
Corrected minor mistake
mushfikurr 08bb4f4
added sneks, exceptions and quiz
19f11fc
fixed the indention
5b3ab0a
Search is now un-casesensitive
mushfikurr b5aa9aa
Added some docstrings. Pep8 stuffs
mushfikurr bf4115c
Merge pull request #3 from discord-python/master
6d7284d
Delete settings.json
a57fbfc
Moar docstrings.
mushfikurr 3d0ed63
Docstrings.
mushfikurr 105049d
added json support for quizs, also random now, requires more questions
60d549d
Final commit, added questions.
mushfikurr 027c416
Delete snake_json
69a2ac1
Delete scientific-snake-names.txt
556b5ea
Delete snektest.txt
1590587
Delete __init__.py
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,9 @@ coverage.xml | |
*.cover | ||
.hypothesis/ | ||
|
||
# VSCode | ||
.vscode/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
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.
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,63 @@ | ||
import json | ||
|
||
import aiohttp | ||
|
||
""" | ||
|
||
Handle requests and grab and returns detail from wikipedia using MediaWiki. | ||
|
||
""" | ||
|
||
|
||
async def get_json(url): | ||
""" Returns the text from request to url """ | ||
async with aiohttp.ClientSession() as session: | ||
async with session.get(url) as resp: | ||
return await resp.text() | ||
|
||
|
||
def get_all_snek(): | ||
"""" Gets all valid snake from a text file """ | ||
file_save = open("bot/snakedata/common-snake-names.txt", "r") | ||
snake_text = file_save.read() | ||
snake_names = snake_text.split("\n") | ||
print("Returned all snake names") | ||
return snake_names | ||
|
||
|
||
async def get_raw_json(name): | ||
""" Returns a dictionary from the JSON grabbed from MediaWiki API. """ | ||
api_url = f'https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts|pageimages&exintro=&explaintext=&titles={name}&redirects=1' | ||
raw_json = await get_json(api_url) | ||
clean_json = json.loads(raw_json) | ||
return clean_json | ||
|
||
|
||
async def get_snek_description(name: str = None): | ||
""" Returns 'extract' text from JSON, using a dictionary """ | ||
json_dict = await get_raw_json(name) | ||
return list(json_dict['query']['pages'].values())[0]['extract'] | ||
|
||
|
||
async def get_snek_scientific(name: str = None): | ||
""" Returns 'title' text from JSON, using a dictionary """ | ||
json_dict = await get_raw_json(name) | ||
scientific = list(json_dict['query']['pages'].values())[0]['title'] | ||
if scientific == name: | ||
return None | ||
else: | ||
return scientific | ||
|
||
|
||
async def get_snek_thumbnail(name: str = None): | ||
""" Returns 'thumbnail' source from JSON, using a dictionary """ | ||
json_dict = await get_raw_json(name) | ||
return list(json_dict['query']['pages'].values())[0]['thumbnail']['source'] | ||
|
||
|
||
async def get_snek_url(name: str = None): | ||
""" Returns the url of the snake searched """ | ||
json_dict = await get_raw_json(name) | ||
title = list(json_dict['query']['pages'].values())[0]['title'] | ||
url = f'https://en.wikipedia.org/wiki/{title}' | ||
return url |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not json.loads inside this function so that you don't have to repeat code in future usages of this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.