Browse Source

correction token RTE

master
nemesis 2 years ago
parent
commit
e665b335d8
  1. 26
      asmodee.py

26
asmodee.py

@ -25,7 +25,9 @@ import json
bot = None
PREFIX = '!'
USERNAME = ""
oauth = None #Appels RTE
RTE_ID = None # Bot's RTE ID
RTE_SECRET = None # Bot's RTE SECRET
#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'
commune_url = 'https://geo.api.gouv.fr/communes?<TYPE>=<NOM>&fields=nom,code,codesPostaux,population&format=json'
@ -1634,6 +1636,7 @@ async def ecowatt(room, message):
global wattobj
if (wattobj.jour < jn or (wattobj.jour == jn and wattobj.heure + 1 < hn)):
try:
oauth = rte_token()
result = oauth.get(ecowatt_url)
watt = json.loads(result.text)
except Exception as e:
@ -1694,6 +1697,7 @@ async def commune(room, message):
cette_commune = commune_url.replace("<NOM>", ville).replace("<TYPE>", "codePostal")
else:
cette_commune = commune_url.replace("<NOM>", ville).replace("<TYPE>", "nom")
oauth = rte_token()
result = oauth.get(cette_commune)
villes = json.loads(result.text)
if (len(villes) > 0):
@ -1730,6 +1734,7 @@ async def eau(room, message):
cette_commune = eau_url.replace("<NOM>", ville).replace("<TYPE>", "code_commune")
else:
cette_commune = eau_url.replace("<NOM>", ville).replace("<TYPE>", "nom_commune")
oauth = rte_token()
result = oauth.get(cette_commune)
eaux = json.loads(result.text)
if (len(eaux["data"]) > 0):
@ -2009,6 +2014,13 @@ async def callStats(room, message):
if match.is_not_from_this_bot():
statistiques(room, message)
def rte_token():
auth = HTTPBasicAuth(RTE_ID, RTE_SECRET)
client = BackendApplicationClient(client_id=RTE_ID)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url='https://digital.iservices.rte-france.com/token/oauth/', auth=auth)
return(oauth)
def main():
config = configparser.ConfigParser()
config.read('asmodee.ini')
@ -2025,20 +2037,16 @@ def main():
else:
print("Probleme de lecture de configuration asmodee.ini (AUTH)")
RTE_ID = None # Bot's RTE ID
RTE_SECRET = None # Bot's RTE SECRET
if ('RTE' in config):
global oauth
global RTE_ID
global RTE_SECRET
global wattobj
RTE_ID = config['RTE']['client_id'] # Bot's username
RTE_SECRET = config['RTE']['client_secret'] # Bot's password
auth = HTTPBasicAuth(RTE_ID, RTE_SECRET)
client = BackendApplicationClient(client_id=RTE_ID)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url='https://digital.iservices.rte-france.com/token/oauth/', auth=auth)
wattobj = Wattobject()
else:
RTE_ID = None
RTE_SECRET = None
print("Probleme de lecture de configuration asmodee.ini (RTE)")
global liste_mod

Loading…
Cancel
Save