Skip to content
This repository was archived by the owner on Mar 14, 2021. It is now read-only.

Team 21 #12

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open

Team 21 #12

wants to merge 42 commits into from

Conversation

eivl
Copy link

@eivl eivl commented Mar 23, 2018

… more testing but not code.

@gdude2002 gdude2002 changed the title testfile for testing commiting inside my text editor. can be used for… Team 22 Mar 23, 2018
Copy link
Contributor

@gdude2002 gdude2002 left a 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?

eivl and others added 25 commits March 25, 2018 13:56
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.
@eivl
Copy link
Author

eivl commented Mar 25, 2018

so does it work now?

@eivl
Copy link
Author

eivl commented Mar 25, 2018

flake8 error fixed

Copy link
Author

@eivl eivl left a comment

Choose a reason for hiding this comment

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

file not needed.

@gdude2002 gdude2002 changed the title Team 22 Team 21 Mar 25, 2018
:return: A dict containing information on a snake
"""
snake_info = {}
# python (programming language) pageid = 23862
URL = "https://en.wikipedia.org/w/api.php?"
Copy link
Contributor

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?

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)
Copy link
Contributor

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.

'.svg',
'ange.',
'Adder%20(PSF).png'
]
Copy link
Contributor

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

Copy link

@TildeBeta TildeBeta Mar 25, 2018

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 ¯\_(ツ)_/¯

'Adder%20(PSF).png'
]
for image in snake_info["images"]:
i = image["title"].split(':')[1].replace(" ", "%20")
Copy link
Contributor

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
Copy link
Contributor

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?

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():
Copy link
Contributor

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

Copy link
Member

@lemonsaurus lemonsaurus left a 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

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)
Copy link
Member

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.

try:
PAGEID = j["query"]["search"][0]["pageid"]
except KeyError:
PAGEID = 41118
Copy link
Member

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

'Adder%20(PSF).png'
]
for image in snake_info["images"]:
i = image["title"].split(':')[1].replace(" ", "%20")
Copy link
Member

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.

if not i.startswith('Map'):
for b in banned:
image_banned = False
if b in i:
Copy link
Member

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():
Copy link
Member

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)

'.svg',
'ange.',
'Adder%20(PSF).png'
]
Copy link
Member

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.

Copy link

@Zwork101 Zwork101 left a 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]:
Copy link

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 = {
Copy link

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"]
Copy link

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 = [
Copy link

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!
Copy link

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'
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants