Skip to content

Instantly share code, notes, and snippets.

@v4lli
Created May 5, 2021 21:11
Show Gist options
  • Select an option

  • Save v4lli/a4c521346222b0c6319209211a5b06b2 to your computer and use it in GitHub Desktop.

Select an option

Save v4lli/a4c521346222b0c6319209211a5b06b2 to your computer and use it in GitHub Desktop.

Revisions

  1. v4lli created this gist May 5, 2021.
    41 changes: 41 additions & 0 deletions meteocool_client.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #!/usr/bin/env python3
    import requests

    # quick & dirty script, plz don't judge

    def get_intensity(meteo_object: object):
    if "reported_intensity" in meteo_object:
    return meteo_object["reported_intensity"]

    def get_intensity_str(meteo_object: object):
    if "reported_intensity" in meteo_object:
    return str(meteo_object["reported_intensity"])

    def get_intensity_emoji(intensity: float):
    if intensity > 60:
    return ":exploding_head:"
    if intensity > 40:
    return ":thunder_cloud_rain:"
    if intensity > 15:
    return ":cloud_rain:"
    if intensity > 0:
    return ":white_sun_rain_cloud:"

    return ":sunny:️"

    def get_rain(location: tuple):
    lat, lon = location
    ret = requests.get(f"https://api.ng.meteocool.com/api/radar/{lat}/{lon}/")
    if ret.status_code != 200:
    return "API error"

    json_ret = ret.json()
    if ("nowcast" not in json_ret) or len(json_ret["nowcast"]) == 0:
    return "Server is still processing, please try again in 1 minute"

    # convert to slack/discord emojis:
    # return " ".join(map(get_intensity_emoji, map(get_intensity, json_ret["nowcast"])))
    return ", ".join(map(get_intensity_str, json_ret["nowcast"]))

    if __name__ == "__main__":
    print(get_rain((49.0, 13.0)))