new api IT WORKS !
This commit is contained in:
parent
c2b3f9650b
commit
ddc7446d8c
40
main.py
40
main.py
@ -9,10 +9,12 @@ import subprocess
|
|||||||
|
|
||||||
# Configuration de l'API REFMAR
|
# Configuration de l'API REFMAR
|
||||||
# API_URL = "https://services.data.shom.fr/maregraphie/service/completetidegauge"
|
# API_URL = "https://services.data.shom.fr/maregraphie/service/completetidegauge"
|
||||||
API_URL = "https://services.data.shom.fr/maregraphie/observation/json"
|
# API_URL = "https://services.data.shom.fr/maregraphie/observation/json"
|
||||||
# curl -X GET "https://services.data.shom.fr/maregraphie/observation/json/386?sources=1&dtStart=2025-05-22T15%3A56%3A00Z&dtEnd=2025-05-22T15%3A57%3A00Z&interval=1" -H "accept: application/json"
|
# curl -X GET "https://services.data.shom.fr/maregraphie/observation/json/386?sources=1&dtStart=2025-05-22T15%3A56%3A00Z&dtEnd=2025-05-22T15%3A57%3A00Z&interval=1" -H "accept: application/json"
|
||||||
# API_KEY = "votre_cle_api" # Remplacez par votre clé API
|
# API_KEY = "votre_cle_api" # Remplacez par votre clé API
|
||||||
STATION = '386' # Identifiant de la station du Havre
|
# STATION = '386' # Identifiant de la station du Havre
|
||||||
|
|
||||||
|
API_URL = "https://data.haropaport.com/sig/capteur/hauteur"
|
||||||
|
|
||||||
UDP_IP = "127.0.0.1"
|
UDP_IP = "127.0.0.1"
|
||||||
UDP_PORT = 8765
|
UDP_PORT = 8765
|
||||||
@ -28,13 +30,13 @@ def fetch_data():
|
|||||||
# "Ocp-Apim-Subscription-Key": API_KEY,
|
# "Ocp-Apim-Subscription-Key": API_KEY,
|
||||||
}
|
}
|
||||||
params = {
|
params = {
|
||||||
"sources": 1,
|
# "sources": 1,
|
||||||
"dtStart": "2025-05-22T10:00:00Z",
|
# "dtStart": "2025-05-22T10:00:00Z",
|
||||||
"dtEnd": "2025-05-22T17:00:00Z",
|
# "dtEnd": "2025-05-22T17:00:00Z",
|
||||||
# "interval": 1
|
# # "interval": 1
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
response = requests.get(API_URL+"/"+STATION, headers=headers, params=params)
|
response = requests.get(API_URL, headers=headers, params=params)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
@ -44,12 +46,11 @@ def fetch_data():
|
|||||||
def process_data(data):
|
def process_data(data):
|
||||||
"""Traite les données récupérées."""
|
"""Traite les données récupérées."""
|
||||||
try:
|
try:
|
||||||
zh_ref = data.get("verticalRef", {}).get("zh_ref", 0)
|
for item in data['items']:
|
||||||
logging.info(f"Hauteur de la marée : {zh_ref} mètres")
|
if item['id'] == "hauteur_shom":
|
||||||
zh_ref_bytes = f"{zh_ref};".encode('utf-8')
|
logging.info(f"{item["capteur"]} Hauteur d'eau : {item["valeur"]} mètres")
|
||||||
sock.sendto(zh_ref_bytes, (UDP_IP, UDP_PORT))
|
hauteurdeau_bytes = f"{item["valeur"]};".encode('utf-8')
|
||||||
# sock.sendto(float(zh_ref).to_bytes(8, byteorder='big'), (UDP_IP, UDP_PORT))
|
sock.sendto(hauteurdeau_bytes, (UDP_IP, UDP_PORT))
|
||||||
# sock.sendto(float(zh_ref), (UDP_IP, UDP_PORT))
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Erreur lors du traitement des données : {e}")
|
logging.error(f"Erreur lors du traitement des données : {e}")
|
||||||
|
|
||||||
@ -58,22 +59,21 @@ def main():
|
|||||||
logging.info("Démarrage de l'application de traitement des données du marégraphe.")
|
logging.info("Démarrage de l'application de traitement des données du marégraphe.")
|
||||||
# lancement du patch pd
|
# lancement du patch pd
|
||||||
pd_patch = "./maregraphe.pd" # Remplace par le chemin de ton patch
|
pd_patch = "./maregraphe.pd" # Remplace par le chemin de ton patch
|
||||||
pd_process = subprocess.Popen(["pd", "-nogui", "-open", pd_patch])
|
# pd_process = subprocess.Popen(["pd", "-nogui", "-open", pd_patch])
|
||||||
|
pd_process = subprocess.Popen(["pd", "-open", pd_patch])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
print('/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / /')
|
print('/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / /')
|
||||||
data = fetch_data()
|
data = fetch_data()
|
||||||
logging.info(json.dumps(data, indent=2))
|
# logging.info(json.dumps(data, indent=2))
|
||||||
# print(data)
|
if data:
|
||||||
# if data:
|
process_data(data)
|
||||||
# process_data(data)
|
time.sleep(10) # 300 Attendre 5 minutes
|
||||||
time.sleep(60) # 300 Attendre 5 minutes
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Arrêt du script, fermeture de Pure Data...")
|
print("Arrêt du script, fermeture de Pure Data...")
|
||||||
pd_process.terminate()
|
pd_process.terminate()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user