first commit

This commit is contained in:
tfa
2022-12-06 12:15:12 +01:00
commit 933a45f2a8
3 changed files with 74 additions and 0 deletions

6
base-config.yaml Normal file
View File

@@ -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"

10
maubot.yaml Normal file
View File

@@ -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

58
rte.py Normal file
View File

@@ -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"] + " : <br />"
for value in values :
if value["hvalue"] == 3: #Rouge
respText += str(value["pas"]) + "H : " + '&#x1F7E5;<br />'
elif value["hvalue"] == 2: #Orange
respText += str(value["pas"]) + "H : " + '&#x1F7E7;<br />'
else : #vert
respText += str(value["pas"]) + "H : " + '&#x1F7E9;<br />'
await evt.respond(respText, allow_html=True)
@classmethod
def get_config_class(cls) -> Type[BaseProxyConfig]:
return Config