first commit
This commit is contained in:
6
base-config.yaml
Normal file
6
base-config.yaml
Normal 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
10
maubot.yaml
Normal 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
58
rte.py
Normal 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 : " + '🟥<br />'
|
||||||
|
elif value["hvalue"] == 2: #Orange
|
||||||
|
respText += str(value["pas"]) + "H : " + '🟧<br />'
|
||||||
|
else : #vert
|
||||||
|
respText += str(value["pas"]) + "H : " + '🟩<br />'
|
||||||
|
|
||||||
|
|
||||||
|
await evt.respond(respText, allow_html=True)
|
||||||
|
@classmethod
|
||||||
|
def get_config_class(cls) -> Type[BaseProxyConfig]:
|
||||||
|
return Config
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user