Python

Force et direction du vent

FFVL

Liste des balises : https://data.ffvl.fr/json/balises.json
Relevés : https://data.ffvl.fr/json/relevesmeteo.json

Pioupiou

Liste des balises et relevés : https://api.pioupiou.fr/v1/live/all

Prévision pluie heure par heure

Lib :

pip install meteofrance-api

Code :

from meteofrance_api import MeteoFranceClient
import time

client = MeteoFranceClient()
rain = client.get_rain(latitude=49.276437, longitude=-0.703140)
for forecast in rain.forecast:
    hour = time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(forecast['dt']))
    print(hour, forecast['desc'], forecast['rain'])

Sortie :

12/07/2023 13:30:00 Temps sec 1
12/07/2023 13:35:00 Temps sec 1
12/07/2023 13:40:00 Temps sec 1
12/07/2023 13:45:00 Temps sec 1
12/07/2023 13:50:00 Temps sec 1
12/07/2023 13:55:00 Temps sec 1
12/07/2023 14:05:00 Temps sec 1
12/07/2023 14:15:00 Temps sec 1
12/07/2023 14:25:00 Temps sec 1

Détermination du jour et de la nuit

pip install pyephem
import ephem
import datetime
import math

# Parameters : latitude, longitude and timestamp utc of observer
# Return : the height of the sun
def sun_height(latitude, longitude, timestamp):
    observer = ephem.Observer()
    observer.lat = latitude * math.pi / 180.0
    observer.lon = longitude * math.pi / 180.0
    observer.date = datetime.datetime.fromtimestamp(timestamp).strftime("%Y/%m/%d %H:%M:%S")
    sun = ephem.Sun(observer)
    return sun.alt * 180.0 / math.pi

# If the top of the sun is higher than the horizon (Diameter of sun = 0.5 degrees)
if sun_height(49.276437, -0.703140, 1689161276) > -0.25:
    print('jour')
else:
    print('nuit')

Téléchargement de météogramme

import requests
from lxml import etree
from io import StringIO

def download_meteogramme(url_page, fichier_telecharge):
    username = "************"
    password = "************"
    url = "https://www.meteoblue.com/fr/user/login/index"
    session = requests.Session()
    response = session.get(url)
    if response.status_code == 200:
        parser = etree.HTMLParser()
        tree = etree.parse(StringIO(response.text), parser)
        csrf = tree.find("//input[@id='csrf']")
        csrf_name = csrf.get('name')
        csrf_value = csrf.get('value')
        data = {"username": username, "password": password, csrf_name: csrf_value}
        response = session.post(url, data=data)
        url = url_page
        response = session.get(url)
        if response.status_code == 200:
            html = etree.HTML(response.content)
            div = html.xpath("//div[@id='blooimage']")[0]
            img_url = f'https:{div.get("data-href")}'
            response = requests.get(img_url)
            with open(fichier_telecharge, "wb") as f:
                f.write(response.content) 
    else:
        print("Error:", response.status_code)