This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

radio weather: use openmeteo instead of openweather (which is no more open)

+83 -33
-14
2configs/services/radio/weather.nix
··· 14 14 ]}" 15 15 curl -fSsz /tmp/GeoLite2-City.mmdb -o /tmp/GeoLite2-City.mmdb http://c.r/GeoLite2-City.mmdb 16 16 MAXMIND_GEOIP_DB="/tmp/GeoLite2-City.mmdb"; export MAXMIND_GEOIP_DB 17 - OPENWEATHER_API_KEY=$(cat "$CREDENTIALS_DIRECTORY/openweather_api"); export OPENWEATHER_API_KEY 18 17 ( 19 18 curl -sS 'http://admin:hackme@localhost:8000/admin/listclients.json?mount=/radio.ogg' 20 19 curl -sS 'http://admin:hackme@localhost:8000/admin/listclients.json?mount=/radio.mp3' ··· 52 51 startAt = "*:58:00"; 53 52 serviceConfig = { 54 53 User = "radio-news"; 55 - LoadCredential = [ 56 - "openweather_api:${config.clanCore.facts.services.weather.secret.openweather_api_key.path}" 57 - ]; 58 54 }; 59 - }; 60 - clanCore.facts.services.weather = { 61 - secret."openweather_api_key" = { }; 62 - generator.script = '' 63 - cat > "$secrets"/openweather_api_key; 64 - ''; 65 - generator.prompt = '' 66 - goto https://openweathermap.org/appid and get an api key 67 - ''; 68 - 69 55 }; 70 56 }
+83 -19
2configs/services/radio/weather_for_ips.py
··· 6 6 import random 7 7 8 8 9 + # https://open-meteo.com/en/docs 10 + def weather_code_representation(code: int) -> str: 11 + if code == 0: 12 + return 'clear sky' 13 + if code == 1: 14 + return 'mainly clear' 15 + if code == 2: 16 + return 'partly cloudy' 17 + if code == 3: 18 + return 'overcast' 19 + if code == 45: 20 + return 'fog' 21 + if code == 48: 22 + return 'depositing rime fog' 23 + if code == 51: 24 + return 'light drizzle' 25 + if code == 53: 26 + return 'moderate drizzle' 27 + if code == 55: 28 + return 'heavy drizzle' 29 + if code == 56: 30 + return 'light freezing drizzle' 31 + if code == 57: 32 + return 'heavy freezing drizzle' 33 + if code == 61: 34 + return 'light rain' 35 + if code == 63: 36 + return 'moderate rain' 37 + if code == 65: 38 + return 'heavy rain' 39 + if code == 66: 40 + return 'light freezing rain' 41 + if code == 67: 42 + return 'heavy freezing rain' 43 + if code == 71: 44 + return 'light snow' 45 + if code == 73: 46 + return 'moderate snow' 47 + if code == 75: 48 + return 'heavy snow' 49 + if code == 77: 50 + return 'light snow grains' 51 + if code == 80: 52 + return 'light rain showers' 53 + if code == 81: 54 + return 'moderate rain showers' 55 + if code == 82: 56 + return 'heavy rain showers' 57 + if code == 85: 58 + return 'light snow showers' 59 + if code == 86: 60 + return 'heavy snow showers' 61 + if code == 95: 62 + return 'thunderstorm' 63 + if code == 96: 64 + return 'thunderstorm with light hail' 65 + if code == 99: 66 + return 'thunderstorm with heavy hail' 67 + return f'unknown weather code {code}' 68 + 69 + 70 + def downfall_representation(precipitation: float) -> str: 71 + if precipitation > 0: 72 + return f' the precipitation is {precipitation} millimeter' 73 + else: 74 + return '' 75 + 9 76 geoip = geoip2.database.Reader(os.environ['MAXMIND_GEOIP_DB']) 10 77 seen = {} 11 78 output = [] ··· 23 90 location = geoip.city(ip.strip()) 24 91 if location.city.geoname_id not in seen: 25 92 seen[location.city.geoname_id] = True 26 - weather_api_key = os.environ['OPENWEATHER_API_KEY'] 27 93 url = ( 28 - f'https://api.openweathermap.org/data/2.5/onecall' 29 - f'?lat={location.location.latitude}' 30 - f'&lon={location.location.longitude}' 31 - f'&appid={weather_api_key}' 32 - f'&units=metric' 94 + f'https://api.open-meteo.com/v1/forecast' 95 + f'?latitude={location.location.latitude}' 96 + f'&longitude={location.location.longitude}' 97 + f'&current=temperature_2m,weather_code' 33 98 ) 34 99 resp = requests.get(url) 35 100 weather = json.loads(resp.text) 36 101 output.append( 37 102 f'{location.city.name}, {location.country.name}. ' 38 - f'{weather["current"]["weather"][0]["description"]}. ' 39 - f'{weather["current"]["temp"]:.1f} degrees.' 103 + f'{weather_code_representation(weather["current"]["weather_code"])}. ' 104 + f'{weather["current"]["temperature_2m"]} degrees.' 40 105 ) 41 106 except: # noqa E722 42 107 pass ··· 57 122 location = geoip.city(ip.strip()) 58 123 if location.city.geoname_id not in seen: 59 124 seen[location.city.geoname_id] = True 60 - weather_api_key = os.environ['OPENWEATHER_API_KEY'] 61 125 url = ( 62 - f'https://api.openweathermap.org/data/2.5/onecall' 63 - f'?lat={location.location.latitude}' 64 - f'&lon={location.location.longitude}' 65 - f'&appid={weather_api_key}' 66 - f'&units=metric' 126 + f'https://api.open-meteo.com/v1/forecast' 127 + f'?latitude={location.location.latitude}' 128 + f'&longitude={location.location.longitude}' 129 + '&current=temperature_2m,precipitation,weather_code,relative_humidity_2m,wind_speed_10m' 130 + '&wind_speed_unit=ms' 67 131 ) 68 132 resp = requests.get(url) 69 133 weather = json.loads(resp.text) 70 134 output.append( 71 135 f'Weather report for {location.city.name}, {location.country.name}. ' 72 - f'It is {weather["current"]["weather"][0]["description"]} outside ' 73 - f'with a temperature of {weather["current"]["temp"]:.1f} degrees, ' 74 - f'a wind speed of {weather["current"]["wind_speed"]:.1f} meters per second ' 75 - f'and a humidity of {weather["current"]["humidity"]} percent. ' 76 - f'The probability of precipitation is {weather["hourly"][0]["pop"] * 100:.0f} percent. ' 136 + f'It is {weather_code_representation(weather["current"]["weather_code"])} outside' 137 + f'{downfall_representation(weather["current"]["precipitation"])}, ' 138 + f'with a temperature of {weather["current"]["temperature_2m"]} degrees, ' 139 + f'a wind speed of {weather["current"]["wind_speed_10m"]} meters per second ' 140 + f'and a humidity of {weather["current"]["relative_humidity_2m"]} percent. ' 77 141 ) 78 142 except: # noqa E722 79 143 pass