Conversation
…meme. I fixed this problem.If users enter "!meme", this bot can send a meme.
jooshua-inglis
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
this can be done with
json_data = response.json()| """ | ||
| url = "https://zenquotes.io/api/random" | ||
| response = requests.get(url) | ||
| headers = {'user-agent': 'vscode-restclient'} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
| 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") |
|
|
||
| # if the message contains negative words | ||
| if any(word in message.content for word in sad_words): | ||
| json_data = get_quote() |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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
| now = datetime.now().strftime('%H:%M') | |
| now = datetime.now(tz=zoneinfo.ZoneInfo("Australia/Brisbane")).strftime('%H:%M') |
and import zoneinfo at the top
No description provided.