jdemaeyer / brightsky

JSON API for DWD's open weather data.
https://brightsky.dev/
MIT License
287 stars 18 forks source link

Add all Mosmix fields to /weather #158

Open df1paw opened 8 months ago

df1paw commented 8 months ago

Would it be possible to add all Mosmix fields to the /Weather API? Details of the parameters available are provided in the following DWD Excel file: Download Of interest would be e.g. significant weather - fog, clouds <500ft Many thanks!

jdemaeyer commented 8 months ago

Hi @df1paw, thanks for reaching out!

I probably won't implement all MOSMIX fields in Bright Sky as that doesn't play well with how the database is currently organized (unifying forecasted and historical records in a single table), scaling from the current ~20 fields to roughly 10x that would come with a massive cost in database size.

However, it's quite straightforward to extract additional fields by directly using dwdparse, which contains Bright Sky's parsing logic, in Python:

from dwdparse import parse_url
from dwdparse.parsers import MOSMIXParser

MOSMIX_S_URL = (
    'https://opendata.dwd.de/weather/local_forecasts/mos/MOSMIX_S/'
    'all_stations/kml/MOSMIX_S_LATEST_240.kmz'
)

class ExtraMOSMIXParser(MOSMIXParser):
    ELEMENTS = {
        **MOSMIXParser.ELEMENTS,
        'N05': 'fog_below_500ft',
    }

for record in parse_url(MOSMIX_S_URL, parser=ExtraMOSMIXParser()):
    # Your processing here...
    print(record)

Is that something that could work for you?