commit 933a45f2a80ef2bf0bf608f1758289329719d0c0 Author: tfa Date: Tue Dec 6 12:15:12 2022 +0100 first commit diff --git a/base-config.yaml b/base-config.yaml new file mode 100644 index 0000000..e09f3f5 --- /dev/null +++ b/base-config.yaml @@ -0,0 +1,6 @@ +auth_url: "https://digital.iservices.rte-france.com/token/oauth/" +token: "RTE_API_TOKEN" +#ecowatt_url: "https://digital.iservices.rte-france.com/open_api/ecowatt/v4/signals" +#Pour la sendbox, commenter la ligne ci-dessus et décommenter la ligne ci-dessous +ecowatt_url: "https://digital.iservices.rte-france.com/open_api/ecowatt/v4/sandbox/signals" + diff --git a/maubot.yaml b/maubot.yaml new file mode 100644 index 0000000..8dc602e --- /dev/null +++ b/maubot.yaml @@ -0,0 +1,10 @@ +maubot: 0.1.0 +id: tfa.rte +version: 0.0.1 +license: AGPL-3.0-or-later +modules: +- rte +main_class: Rte +config: true +extra_files: +- base-config.yaml diff --git a/rte.py b/rte.py new file mode 100644 index 0000000..0eca2e4 --- /dev/null +++ b/rte.py @@ -0,0 +1,58 @@ +from typing import Type +from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper +from maubot import Plugin, MessageEvent +from maubot.handlers import command +from datetime import datetime +import aiohttp +import asyncio +import json + + +class Config(BaseProxyConfig): + def do_update(self, helper: ConfigUpdateHelper) -> None: + helper.copy("auth_url") + helper.copy("token") + helper.copy("ecowatt_url") + + +class Rte(Plugin): + async def start(self) -> None: + self.config.load_and_update() + + + @command.new(name="rte", help="") + async def get_eco_watt(self, evt: MessageEvent) -> None: + await evt.mark_read() + resp = await self.http.post(self.config["auth_url"], headers={'Authorization' : 'Basic ' + self.config["token"]}) + ans = await resp.text() + objet = json.loads(ans) + bearer = objet["access_token"] + + resp = await self.http.get(self.config["ecowatt_url"], headers={'Authorization' : 'Bearer ' + bearer}) + ans = await resp.text() + objet = json.loads(ans) + signals = objet["signals"] + for signal in signals: + heure = datetime.fromisoformat(signal["jour"]) + if signal["dvalue"] == 1: + await evt.respond(heure.strftime("%d/%m/%Y") + " : " + signal["message"]) + + else : + values = signal["values"] + respText = heure.strftime("%d/%m/%Y") + " : " + signal["message"] + " :
" + for value in values : + if value["hvalue"] == 3: #Rouge + respText += str(value["pas"]) + "H : " + '🟥
' + elif value["hvalue"] == 2: #Orange + respText += str(value["pas"]) + "H : " + '🟧
' + else : #vert + respText += str(value["pas"]) + "H : " + '🟩
' + + + await evt.respond(respText, allow_html=True) + @classmethod + def get_config_class(cls) -> Type[BaseProxyConfig]: + return Config + + +