generated from Nemesis/Exemple
eau
This commit is contained in:
parent
917d4d9d88
commit
ad0087e8cb
2 changed files with 64 additions and 7 deletions
|
@ -5,8 +5,8 @@ server = https://instance.tld
|
||||||
admin = @mxid:intance.tld
|
admin = @mxid:intance.tld
|
||||||
|
|
||||||
[MOD]
|
[MOD]
|
||||||
# liste = roll,quote,biere,stats,liste,horloge,carte,card,cristal,welcome,salut,jdr,gens,va,salon,kick,mails,titre,invidious,ecowatt,commune
|
# liste = roll,quote,biere,stats,liste,horloge,carte,card,cristal,welcome,salut,jdr,gens,va,salon,kick,mails,titre,invidious,ecowatt,commune,eau
|
||||||
liste = roll,quote,biere,stats,liste,horloge,carte,card,cristal,welcome,salut,jdr,gens,va,salon,kick,mails,titre,invidious,ecowatt,commune
|
liste = roll,quote,biere,stats,liste,horloge,carte,card,cristal,welcome,salut,jdr,gens,va,salon,kick,mails,titre,invidious,ecowatt,commune,eau
|
||||||
|
|
||||||
[MAIL]
|
[MAIL]
|
||||||
malt = 0
|
malt = 0
|
||||||
|
|
67
asmodee.py
67
asmodee.py
|
@ -28,7 +28,9 @@ USERNAME = ""
|
||||||
oauth = None #Appels RTE
|
oauth = None #Appels RTE
|
||||||
#ecowatt_url = 'https://digital.iservices.rte-france.com/open_api/ecowatt/v4/sandbox/signals'
|
#ecowatt_url = 'https://digital.iservices.rte-france.com/open_api/ecowatt/v4/sandbox/signals'
|
||||||
ecowatt_url = 'https://digital.iservices.rte-france.com/open_api/ecowatt/v4/signals'
|
ecowatt_url = 'https://digital.iservices.rte-france.com/open_api/ecowatt/v4/signals'
|
||||||
commune_url = 'https://geo.api.gouv.fr/communes?nom=<NOM>&fields=codesPostaux,population&format=json'
|
commune_url = 'https://geo.api.gouv.fr/communes?<TYPE>=<NOM>&fields=nom,code,codesPostaux,population&format=json'
|
||||||
|
eau_url = 'https://hubeau.eaufrance.fr/api/vbeta/qualite_eau_potable/resultats_dis?<TYPE>=<NOM>&size=1'
|
||||||
|
|
||||||
wattobj = None
|
wattobj = None
|
||||||
|
|
||||||
# Listes et dictionnaires
|
# Listes et dictionnaires
|
||||||
|
@ -1679,22 +1681,71 @@ async def commune(room, message):
|
||||||
mess = ""
|
mess = ""
|
||||||
if (len(args) > 0):
|
if (len(args) > 0):
|
||||||
ville = " ".join(args)
|
ville = " ".join(args)
|
||||||
cette_commune = commune_url.replace("<NOM>", ville)
|
cette_commune = None
|
||||||
|
if (ville.isnumeric()):
|
||||||
|
cette_commune = commune_url.replace("<NOM>", ville).replace("<TYPE>", "codePostal")
|
||||||
|
else:
|
||||||
|
cette_commune = commune_url.replace("<NOM>", ville).replace("<TYPE>", "nom")
|
||||||
result = oauth.get(cette_commune)
|
result = oauth.get(cette_commune)
|
||||||
villes = json.loads(result.text)
|
villes = json.loads(result.text)
|
||||||
if (len(villes) > 0):
|
if (len(villes) > 0):
|
||||||
try:
|
try:
|
||||||
cite = villes[0]
|
cite = villes[0]
|
||||||
code = cite["codesPostaux"][0]
|
codePoste = cite["codesPostaux"][0]
|
||||||
pop = cite["population"]
|
pop = cite["population"]
|
||||||
await msg(room, ville + ". CP : " + code + ". Population : " + str(pop), sender)
|
insee = cite["code"]
|
||||||
|
nom = cite["nom"]
|
||||||
|
await msg(room, nom + ". CP : " + codePoste + ". Code INSEE : " + insee + ". Population : " + str(pop), sender)
|
||||||
except:
|
except:
|
||||||
await msg(room, str(villes), sender)
|
await msg(room, str(villes), sender)
|
||||||
else:
|
else:
|
||||||
await msg(room, "Commune non trouvée", sender)
|
await msg(room, "Commune non trouvée", sender)
|
||||||
else:
|
else:
|
||||||
await msg(room, "!commune <nom de la commune", sender)
|
await msg(room, "!commune <nom de la commune OU code postal de la commune>", sender)
|
||||||
|
|
||||||
|
async def eau(room, message):
|
||||||
|
global modules
|
||||||
|
try:
|
||||||
|
rmod = modules[room.room_id, 'eau']
|
||||||
|
except:
|
||||||
|
modules[room.room_id, 'eau'] = False
|
||||||
|
if (modules[room.room_id, 'eau']):
|
||||||
|
args = getMessage(message).split()
|
||||||
|
sender = getUser(message)
|
||||||
|
args.pop(0)
|
||||||
|
mess = ""
|
||||||
|
if (len(args) > 0):
|
||||||
|
ville = " ".join(args)
|
||||||
|
cette_commune = None
|
||||||
|
if (ville.isnumeric()):
|
||||||
|
cette_commune = eau_url.replace("<NOM>", ville).replace("<TYPE>", "code_commune")
|
||||||
|
else:
|
||||||
|
cette_commune = eau_url.replace("<NOM>", ville).replace("<TYPE>", "nom_commune")
|
||||||
|
result = oauth.get(cette_commune)
|
||||||
|
eaux = json.loads(result.text)
|
||||||
|
if (len(eaux["data"]) > 0):
|
||||||
|
try:
|
||||||
|
eau = eaux["data"][0]
|
||||||
|
nom = eau["nom_commune"]
|
||||||
|
date = eau["date_prelevement"][0:10]
|
||||||
|
res = eau["resultat_alphanumerique"]
|
||||||
|
unite = str(eau["libelle_unite"])
|
||||||
|
if (unite == "SANS OBJET"):
|
||||||
|
unite = ""
|
||||||
|
limite = "(" + str(eau["limite_qualite_parametre"]) + ")"
|
||||||
|
if (limite == "(None)"):
|
||||||
|
limite = ""
|
||||||
|
param = eau["libelle_parametre"] + " " + limite
|
||||||
|
concl = eau["conclusion_conformite_prelevement"]
|
||||||
|
distrib = eau["nom_distributeur"]
|
||||||
|
await msg(room, "Prélèvement à " + nom + " le " + date + ". \nRésultat : " + res + unite + " / " + param + ".\n" + concl + "\n" + distrib, sender)
|
||||||
|
except:
|
||||||
|
await msg(room, str(eaux), sender)
|
||||||
|
else:
|
||||||
|
await msg(room, "Commune non trouvée", sender)
|
||||||
|
else:
|
||||||
|
await msg(room, "!eau <nom de la commune OU code INSEE de la commune>", sender)
|
||||||
|
|
||||||
async def help(room, message): # Aide en message privé
|
async def help(room, message): # Aide en message privé
|
||||||
await help_center(room,message,"help",True)
|
await help_center(room,message,"help",True)
|
||||||
|
|
||||||
|
@ -1799,6 +1850,12 @@ async def callCommune(room, message):
|
||||||
if match.is_not_from_this_bot() and match.prefix() and match.command("commune"):
|
if match.is_not_from_this_bot() and match.prefix() and match.command("commune"):
|
||||||
await commune(room, message)
|
await commune(room, message)
|
||||||
|
|
||||||
|
@bot.listener.on_message_event
|
||||||
|
async def callEau(room, message):
|
||||||
|
match = botlib.MessageMatch(room, message, bot, PREFIX)
|
||||||
|
if match.is_not_from_this_bot() and match.prefix() and match.command("eau"):
|
||||||
|
await eau(room, message)
|
||||||
|
|
||||||
@bot.listener.on_message_event
|
@bot.listener.on_message_event
|
||||||
async def callEcowatt(room, message):
|
async def callEcowatt(room, message):
|
||||||
match = botlib.MessageMatch(room, message, bot, PREFIX)
|
match = botlib.MessageMatch(room, message, bot, PREFIX)
|
||||||
|
|
Loading…
Reference in a new issue