Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add !c saimaa #70

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def start(self):


# Version number
VERSION = "v1.14.14"
VERSION = "v1.14.15"
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from modules import nitro
from modules import dice_comm
from modules import auction
from modules import saimaa

logging.basicConfig(
filename="Coralog.txt",
Expand Down Expand Up @@ -153,6 +154,8 @@ async def on_message(message):
await dice_comm.dice_comm(message)
elif cmd == "status":
await message.channel.send("418 I'm a teapot")
elif cmd == "saimaa":
await saimaa.saimaa(message)
elif cmd == "test":
await message.add_reaction("\N{white heavy check mark}")
else:
Expand Down
39 changes: 39 additions & 0 deletions modules/saimaa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import logging

from discord.errors import Forbidden
from modules.common import forbiddenErrorHandler, get_hex_colour
import discord
import requests

async def saimaa(message):
await message.channel.trigger_typing()
response = requests.get("https://wwwi3.ymparisto.fi/i3/tilanne/fin/Lampotila/data/T0411210.txt", headers={"User-Agent": "Appelsiini1:n Discord Botti"},)
response2 = requests.get("https://wwwi3.ymparisto.fi/i3/tilanne/fin/Lampotila/Lampotila.htm", headers={"User-Agent": "Appelsiini1:n Discord Botti"},)

if response2.status_code == 200 and response.status_code == 200:
date = response.text.split("\n")[0].strip().split(";")[0]
temperature = response.text.split("\n")[0].strip().split(";")[1]
data2 = response2.text.find("<p>Päivitetty")
updated = response2.text[data2:][:30].lstrip("<p>Päivitetty ")

emb = discord.Embed()
emb.title = "The temperature of the Saimaa lake"
emb.description = f"The surface temperature as measured in Lauritsala:\n{date}: **{temperature}°C**"
emb.set_footer(text= f"Source: Finnish Environment Institute (syke.fi)\nUpdated: {updated}")
emb.color = get_hex_colour()

try:
await message.channel.send(embed=emb)
except Forbidden:
await forbiddenErrorHandler(message)
else:
msg = f"Could not fetch temperature info, response codes {response.status_code} and {response2.status_code}"
logging.error(msg)
emb = discord.Embed()
emb.title = msg
emb.color = get_hex_colour(error=True)

try:
await message.channel.send(embed=emb)
except Forbidden:
await forbiddenErrorHandler(message)
5 changes: 4 additions & 1 deletion webhook/versions.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
v1.14.15
- Add '!c saimaa' command to get the surface temperature of the Saimaa lake
###
v1.14.14
- Add `!c tatus` command to check bot status
- Add `!c status` command to check bot status
###
v1.14.13
- Fix nitro boost tracking for the n+1th f*****g time
Expand Down