Created
May 5, 2021 21:11
-
-
Save v4lli/a4c521346222b0c6319209211a5b06b2 to your computer and use it in GitHub Desktop.
Retrieve the currently forecasted rain intensities from the meteocool API. Retunred valued are RVP6 values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment