Skip to content

Commit

Permalink
v0.705 - improved weather data combining
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingFathead committed May 25, 2024
1 parent 0ad8c8f commit 930dff9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ yt-dlp>=2024.3.10
- Use the `configmerger.py` to update old configuration files into a newer version's `config.ini`. You can do this by creating a copy of your existing config to i.e. a file named `myconfig.txt` and including in it the lines you want to keep for the newer version. Then, just run `python configmerger.py config.ini myconfig.txt` and all your existing config lines will be migrated to the new one. Works in most cases, but remember to be careful and double-check any migration issues with i.e. `diff`!

# Changelog
- v0.705 - improved weather data combining; small tweaks
- v0.703 - Language translations and tweaks to WeatherAPI data fetching
- v0.70 - WeatherAPI support added, to enable, get an API key from weatherapi.com
- v0.61 - improved handling of weather and time/data data globally
Expand Down
24 changes: 18 additions & 6 deletions api_get_openweathermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ async def combine_weather_data(city_name, country, lat, lon, current_weather_dat
visibility = current_weather_data.get('visibility', 'N/A')
snow_1h = current_weather_data.get('snow', {}).get('1h', 'N/A')

# UV index from WeatherAPI
# Data to get from WeatherAPI
uv_index = current_weather_data_from_weatherapi['uv_index']
visibility_wapi = current_weather_data_from_weatherapi['visibility']
condition_wapi = current_weather_data_from_weatherapi['condition']

sunrise_time_utc = datetime.datetime.utcfromtimestamp(current_weather_data['sys']['sunrise'])
sunset_time_utc = datetime.datetime.utcfromtimestamp(current_weather_data['sys']['sunset'])
Expand Down Expand Up @@ -194,23 +196,28 @@ async def combine_weather_data(city_name, country, lat, lon, current_weather_dat
f"Minimi: {temp_min}°C / {temp_min_fahrenheit:.1f}°F, Maksimi: {temp_max}°C / {temp_max_fahrenheit:.1f}°F, "
f"Ilmanpaine: {pressure} hPa, Ilmankosteus: {humidity}%, "
f"Tuulen nopeus: {wind_speed} m/s, Tuulen suunta: {wind_direction} astetta ({wind_direction_cardinal}), "
f"Näkyvyys: {visibility} metriä, "
f"Näkyvyys: {visibility} metriä [OpenWeatherMap] | {visibility_wapi} km [WeatherAPI], "
f"Lumisade (viimeisen 1h aikana): {snow_1h} mm, "
f"Auringonnousu: {sunrise_time_local_str}, "
f"Auringonlasku: {sunset_time_local_str}, "
f"Koordinaatit: {coordinates_info} (Maa: {country_info}), "
f"Kuun vaihe: {moon_phase_data}, "
f"UV-indeksi: {uv_index}" # Include UV index in the detailed weather info
f"UV-indeksi [WeatherAPI]: {uv_index}, " # Include UV index in the detailed weather info
f"Sääolosuhteet [WeatherAPI]: {condition_wapi}" # Include 'condition' from WeatherAPI
)

# Include additional WeatherAPI data (daily forecast, air quality, and alerts)
if daily_forecast_data:
air_quality_data = daily_forecast_data['air_quality']
alerts = daily_forecast_data['alerts']

air_quality_info = "\nIlmanlaatu:\n" + "\n".join(
air_quality_info = "\n(Ilmanlaatu: " + " / ".join(
[f"{key}: {value}" for key, value in air_quality_data.items()]
)
) + ")"

# air_quality_info = "\nIlmanlaatu:\n" + "\n".join(
# [f"{key}: {value}" for key, value in air_quality_data.items()]
# )

alerts_info = "\nSäävaroitukset:\n" + (
"\n".join(
Expand Down Expand Up @@ -248,7 +255,12 @@ async def combine_weather_data(city_name, country, lat, lon, current_weather_dat

final_forecast = f"Kolmen tunnin sääennuste, {city_name}:\n" + "\n".join(formatted_forecasts)

combined_info = f"{detailed_weather_info}\n\n{final_forecast}"
additional_info_to_add = (
"NOTE: TRANSLATE AND FORMAT THIS DATA FOR THE USER AS APPROPRIATE. Use emojis where suitable to enhance the readability and engagement of the weather report. "
"For example, use 🌞 for sunny, 🌧️ for rain, ⛅ for partly cloudy, etc and include a relevant and concise overview of what was asked."
)

combined_info = f"{detailed_weather_info}\n\n{final_forecast}\n\n{additional_info_to_add}"
logging.info(f"Formatted combined weather data being sent: {combined_info}")
return combined_info

Expand Down
1 change: 1 addition & 0 deletions api_get_weatherapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ async def get_current_weather_via_weatherapi(location):
'wind': current['wind_kph'],
'precipitation': current['precip_mm'],
'uv_index': current['uv'],
'visibility': current['vis_km'], # Added visibility data
'air_quality': current.get('air_quality', {})
}
else:
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# https://github.com/FlyingFathead/TelegramBot-OpenAI-API
#
# version of this program
version_number = "0.703"
version_number = "0.705"

# experimental modules
import requests
Expand Down

0 comments on commit 930dff9

Please sign in to comment.