Skip to content

Feature/meme#9

Open
takaomizuno0032 wants to merge 7 commits intocodenetwork:mainfrom
takaomizuno0032:feature/meme
Open

Feature/meme#9
takaomizuno0032 wants to merge 7 commits intocodenetwork:mainfrom
takaomizuno0032:feature/meme

Conversation

@takaomizuno0032
Copy link

No description provided.

Copy link

@jooshua-inglis jooshua-inglis left a comment

Choose a reason for hiding this comment

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

Might be a little bit nitpicky, but just a couple of things

response = requests.get(url)
headers = {'user-agent': 'vscode-restclient'}
response = requests.request("GET", zen_url, headers=headers)
json_data = json.loads(response.text)

Choose a reason for hiding this comment

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

this can be done with

json_data = response.json()

"""
url = "https://zenquotes.io/api/random"
response = requests.get(url)
headers = {'user-agent': 'vscode-restclient'}

Choose a reason for hiding this comment

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

Where does this user agent come from?

url = "https://zenquotes.io/api/random"
response = requests.get(url)
headers = {'user-agent': 'vscode-restclient'}
response = requests.request("GET", zen_url, headers=headers)

Choose a reason for hiding this comment

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

might want to do some error checking here, like checking if the status code is between 200 and 299.
I see there is some error checking below, but if an error is going to occur it's likely that no json is going to be send at all, and would fail on line 42 when decoding the json file.

Take a look at this for more details on what I mean. https://stackoverflow.com/questions/16511337/correct-way-to-try-except-using-python-requests-module/16511493#16511493

please refer to this below url
https://github.com/D3vd/Meme_Api
"""
response = requests.request("GET", meme_url)

Choose a reason for hiding this comment

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

same thing here

now = datetime.now().strftime('%H:%M')
if (now == '08:00'):
channel = client.get_channel(meme_channel_id)
await channel.send(f"Good morning! This is today's meme")

Choose a reason for hiding this comment

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

Doesn't need to be an fstring


# if the message contains negative words
if any(word in message.content for word in sad_words):
json_data = get_quote()

Choose a reason for hiding this comment

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

json_data is not a very helpful variable name here. quote_data is probably better

This function sends a meme at 8:00 am everyday.
This task is called every 1 minutes and if the time is 8:00, it will send meme.
"""
now = datetime.now().strftime('%H:%M')

Choose a reason for hiding this comment

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

Oh oh, timezones.

This may work on your machine where time is in our current timezone, but if this is hosted somewhere we can't guarentee that.

We might want to specify the timezone like this

Suggested change
now = datetime.now().strftime('%H:%M')
now = datetime.now(tz=zoneinfo.ZoneInfo("Australia/Brisbane")).strftime('%H:%M')

and import zoneinfo at the top

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants