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

Team 13 #10

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

Team 13 #10

wants to merge 54 commits into from

Conversation

schwartzadev
Copy link

this will hold our submissions for the code jam - thanks for setting this up!

@command()
async def get(self, ctx: Context, name: str = None):
async def get(self, ctx: Context, name: str = "python"):
Copy link
Contributor

Choose a reason for hiding this comment

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

No, this should default to None. The task requires a random snake if the parameter is left out.

Copy link
Author

Choose a reason for hiding this comment

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

yep - just noticed this - thanks!

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.

Keep up the good work!

@@ -40,6 +69,28 @@ def __init__(self, bot: AutoShardedBot):
:param ctx: Context object passed from discord.py
:param name: Optional, the name of the snake to get information for - omit for a random snake
"""
embed = discord.Embed(color=0x3E885B)
if name == "python":
Copy link
Member

Choose a reason for hiding this comment

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

This should be case insensitive.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks - so when I change line 73 to if name.lower() == "python":, I get an error about comparing NoneTypes since the default name is None (see the method declaration). How should I get around this? Should I do an "if None" check before the python special case or should I do something else?

(discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'lower' is the error for reference)

Copy link
Member

Choose a reason for hiding this comment

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

if name and name.lower() == "python":

would work for me.

Copy link
Author

Choose a reason for hiding this comment

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

yep - looks good, thanks

:return: the full JSON from the search API
"""
url = "https://api.unsplash.com/search/photos?client_id" \
"={0}&query={1}+snake".format(os.environ.get("UNSPLASH_CLIENT_ID"), snake_name)
Copy link
Member

Choose a reason for hiding this comment

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

this string is a bit messy. prefer implicit string joins inside paranthesis and f-strings to \ line continuation and formats.

client_id = os.environ.get("UNSPLASH_CLIENT_ID")
url = (
    "https://api.unsplash.com/search/photos?client_id" 
    f"={client_id}&query={snake_name}+snake"
)

@@ -29,6 +35,29 @@ def __init__(self, bot: AutoShardedBot):
:return: A dict containing information on a snake
"""

async def get_snek_qwant_json(self, snake_name):
Copy link
Member

Choose a reason for hiding this comment

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

snake_name should be type hinted, as should the return type.

response = await response.read()
return json.loads(response.decode("utf-8"))

async def get_snek_image(self, name):
Copy link
Member

Choose a reason for hiding this comment

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

name should be type hinted, as should return type.

embed.add_field(
name="Python (programming language)",
value="*Guido van Rossum*\n\n"
"This language is neither dangerous nor venomous and be found in software globally",
Copy link
Member

Choose a reason for hiding this comment

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

Unless you're a pirate, this should be "and can be found".

# handle Python special case
embed.add_field(
name="Python (programming language)",
value="*Guido van Rossum*\n\n"
Copy link
Member

Choose a reason for hiding this comment

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

multiline implicit string joins should be wrapped inside paranthesis, so that it's clear that they're one thing. This is a bit too implicit.

Copy link
Author

Choose a reason for hiding this comment

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

Can you explain this? I'm not super clear as to what you mean...

Copy link
Member

Choose a reason for hiding this comment

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

value=(
    "*Guido van Rossum*\n\n"
    "This language is neither dangerous nor venomous and be found in software globally"
),

this is one way.

or if you prefer it, this is acceptable too

value=("*Guido van Rossum*\n\n"
       "This language is neither dangerous nor venomous and be found in software globally"),

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 wonder why prith didn't push anything except for one commit

@@ -1,15 +1,21 @@
[[source]]

Copy link
Contributor

Choose a reason for hiding this comment

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

There's loads of extra spaces in this file now. Did you edit it by hand?

Copy link
Author

Choose a reason for hiding this comment

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

nope - this happened automatically when I installed the titlecase package

"sha256": "d797e580ddcddc99bf058109ab0306ad584c2902752a3d4076ba713fdc580fb7"
"sha256": "2cca231e2bd4b5fdaa06fd33b68143231524f2855847ebf4cc497462e135fdf2"
},
"host-environment-markers": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh. Where'd this come from? Also, why did you sort all the hashes in this file?

Copy link
Author

Choose a reason for hiding this comment

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

this happened automatically when I installed the titlecase package

"Snakes kill over 40,000 people a year—though, with unreported incidents, the total may be over 100,000. About half of these deaths are in India.",
"Some members of the U.S. Army Special Forces are taught to kill and eat snakes during their survival training, which has earned them the nickname “Snake Eaters.”"
]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing a newline at the end of the file.

async with aiohttp.ClientSession() as session:
async with session.get(url, headers=head) as response:
response = await response.read()
return json.loads(response.decode("utf-8"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't you just use return await response.json()?

@@ -28,8 +75,44 @@ def __init__(self, bot: AutoShardedBot):
:param name: Optional, the name of the snake to get information for - omit for a random snake
:return: A dict containing information on a snake
"""
base_url = "https://protected-reef-75100.herokuapp.com/"
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, that's an odd decision.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get more info on what you're doing here?

Choose a reason for hiding this comment

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

Hey @gdude2002 , that's where we hosted our snake API. Here's the link to the repo. This is where most of my commits are :)


# Any additional commands can be placed here. Be creative, but keep it to a reasonable amount!

@command(aliases=["f"])
async def fact(self, ctx: Context):
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just like to point out that you put a ton of work into the get command, and not much into your extra stuff.

The marking is heavily weighted towards the extra creative stuff. But you still have 12 hours!

@gdude2002
Copy link
Contributor

You code is failing to lint. Please see Travis for more information.

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.

4 participants