From c589e5570918dfb297a0ec7079aeba9c3e9cf6d9 Mon Sep 17 00:00:00 2001 From: Appelsiini1 <37345715+Appelsiini1@users.noreply.github.com> Date: Tue, 20 Jul 2021 22:12:11 +0300 Subject: [PATCH] Add !c saimaa --- constants.py | 2 +- main.py | 3 +++ modules/saimaa.py | 39 +++++++++++++++++++++++++++++++++++++++ webhook/versions.txt | 5 ++++- 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 modules/saimaa.py diff --git a/constants.py b/constants.py index 900abdb..7acca54 100644 --- a/constants.py +++ b/constants.py @@ -64,4 +64,4 @@ def start(self): # Version number -VERSION = "v1.14.14" +VERSION = "v1.14.15" diff --git a/main.py b/main.py index 99861cb..1d3f908 100644 --- a/main.py +++ b/main.py @@ -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", @@ -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: diff --git a/modules/saimaa.py b/modules/saimaa.py new file mode 100644 index 0000000..ba7b758 --- /dev/null +++ b/modules/saimaa.py @@ -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äivitetty") + updated = response2.text[data2:][:30].lstrip("
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) \ No newline at end of file diff --git a/webhook/versions.txt b/webhook/versions.txt index 4576709..eba0b44 100644 --- a/webhook/versions.txt +++ b/webhook/versions.txt @@ -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