-
-
Notifications
You must be signed in to change notification settings - Fork 16
Team 21 #12
base: master
Are you sure you want to change the base?
Team 21 #12
Conversation
… more testing but not code.
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.
I see no changes here - did you forget to push?
commit ba5705b8e9e18d9f8a541dee446da21002853d37 Author: TildeBeta <tildebetabot@gmail.com> Date: Sun Mar 25 14:57:00 2018 +0300 Flake8 fixes and special case handling commit 051952e Author: TildeBeta <tildebetabot@gmail.com> Date: Sun Mar 25 01:01:39 2018 +0200 Fix disambiguator, create a mock embed commit d0d944f Author: TildeBeta <tildebetabot@gmail.com> Date: Sun Mar 25 00:25:25 2018 +0200 Fix up malformed data commit d8d9894 Author: TildeBeta <tildebetabot@gmail.com> Date: Sat Mar 24 20:09:42 2018 +0200 Redundant set cast commit 0984643 Author: TildeBeta <tildebetabot@gmail.com> Date: Sat Mar 24 19:33:29 2018 +0200 Improve disambiguation commit 2124795 Author: TildeBeta <tildebetabot@gmail.com> Date: Sat Mar 24 15:26:55 2018 +0200 Paginate results instead of posting a massive block commit c6112d5 Author: TildeBeta <tildebetabot@gmail.com> Date: Sat Mar 24 14:29:41 2018 +0200 Improve snake name matching
[UPDATE] Ignored a silly rule from flake8.
so does it work now? |
flake8 error fixed |
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.
file not needed.
bot/cogs/snakes.py
Outdated
:return: A dict containing information on a snake | ||
""" | ||
snake_info = {} | ||
# python (programming language) pageid = 23862 | ||
URL = "https://en.wikipedia.org/w/api.php?" |
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.
Constants should probably be at module-level?
bot/cogs/snakes.py
Outdated
PAGE_ID_URL = f"{URL}{FORMAT}&{ACTION}&{LIST}&{SRSEARCH}{name}&{UTF8}&{SRLIMIT}" | ||
|
||
async with aiohttp.ClientSession() as session: | ||
j = await self.fetch(session, PAGE_ID_URL) |
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.
Not a fan of one-letter variable names.
bot/cogs/snakes.py
Outdated
'.svg', | ||
'ange.', | ||
'Adder%20(PSF).png' | ||
] |
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.
These are hilariously arbitrary. What's up? :P
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.
Wikipedia has arbitrary images on their snake pages ¯\_(ツ)_/¯
bot/cogs/snakes.py
Outdated
'Adder%20(PSF).png' | ||
] | ||
for image in snake_info["images"]: | ||
i = image["title"].split(':')[1].replace(" ", "%20") |
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.
Again, I don't love these one-letter variable names
title=data['title'], | ||
description=match.group(1) if match else None, | ||
url=data['fullurl'], | ||
colour=0x59982F |
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.
What colour is this? Is it not included in the discord.Colour
class as a staticmethod?
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.
No it's just a random green I found online
@@ -47,3 +50,18 @@ def in_channel(channel_id): | |||
f"The result of the in_channel check was {check}.") | |||
return check | |||
return commands.check(predicate) | |||
|
|||
|
|||
def locked(): |
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.
Can you comment this? It's not obvious what it does
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.
some minor change requests
bot/cogs/snakes.py
Outdated
PAGE_ID_URL = f"{URL}{FORMAT}&{ACTION}&{LIST}&{SRSEARCH}{name}&{UTF8}&{SRLIMIT}" | ||
|
||
async with aiohttp.ClientSession() as session: | ||
j = await self.fetch(session, PAGE_ID_URL) |
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.
j
is not acceptable as a variable name for this.
bot/cogs/snakes.py
Outdated
try: | ||
PAGEID = j["query"]["search"][0]["pageid"] | ||
except KeyError: | ||
PAGEID = 41118 |
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.
this could use a comment, what the hell is it
bot/cogs/snakes.py
Outdated
'Adder%20(PSF).png' | ||
] | ||
for image in snake_info["images"]: | ||
i = image["title"].split(':')[1].replace(" ", "%20") |
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.
this line is far too dense, and i
is another awful variable name.
bot/cogs/snakes.py
Outdated
if not i.startswith('Map'): | ||
for b in banned: | ||
image_banned = False | ||
if b in i: |
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.
and this line pretty much perfectly illustrates why single letter variables suck.
@@ -47,3 +50,18 @@ def in_channel(channel_id): | |||
f"The result of the in_channel check was {check}.") | |||
return check | |||
return commands.check(predicate) | |||
|
|||
|
|||
def locked(): |
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.
please docstring the decorators as well. I shouldn't have to study this to figure out what that decorator does. (I don't think it's immediately obvious from the name, either)
bot/cogs/snakes.py
Outdated
'.svg', | ||
'ange.', | ||
'Adder%20(PSF).png' | ||
] |
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.
please be consistent about this style choice. Later on you're using the convention that looks like this:
var = (
"contents"
)
This is the style used in all of our open source projects, so we would prefer if you used this style here as well.
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.
Amazing work! You seem to like to have hard coded values and urls in your function. I would move that right next to you regex compiles. Other then that, great bot! See you next code jam!
def __init__(self, bot: AutoShardedBot): | ||
self.bot = bot | ||
|
||
async def get_snek(self, name: str = None) -> Dict[str, Any]: |
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 remove what it returns? That's great documenting!
""" | ||
Go online and fetch information about a snake | ||
async with aiohttp.ClientSession() as session: | ||
params = { |
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.
These don't have to be defined each time it's called, maybe class property?
|
||
# constructing dict - handle exceptions later | ||
try: | ||
snake_info["title"] = json["query"]["pages"][f"{pageid}"]["title"] |
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.
Use loops! That would clean up this hunk of code
thumb_list = [] | ||
|
||
# Wikipedia has arbitrary images that are not snakes | ||
banned = [ |
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.
Once again, hard coded lists should be moved to somewhere such as a class variable
for image in snake_info["images"]: | ||
# images come in the format of `File:filename.extension` | ||
file, sep, filename = image["title"].partition(':') | ||
filename = filename.replace(" ", "%20") # Wikipedia returns good data! |
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.
Use the built-in urllib for this!
|
||
embed.set_footer(text='Powered by Wikipedia') | ||
|
||
emoji = 'https://emojipedia-us.s3.amazonaws.com/thumbs/60/google/3/snake_1f40d.png' |
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.
Yak! Hard coded value inside the function again. Same issue as the list and dicts.
… more testing but not code.