Untitled
unknown
plain_text
2 months ago
3.3 kB
3
Indexable
Never
# Set the API URL set api_url "https://api.open-meteo.com/v1/dwd-icon?latitude=41.57&longitude=23.28&daily=weathercode,temperature_2m_max,temperature_2m_min,apparent_temperature_max,apparent_temperature_min,sunrise,sunset,precipitation_sum,rain_sum,showers_sum,snowfall_sum,precipitation_hours,windspeed_10m_max,windgusts_10m_max,winddirection_10m_dominant,shortwave_radiation_sum,et0_fao_evapotranspiration¤t_weather=true&timeformat=unixtime&timezone=Africa%2FCairo" # Define the commands bind pub - "!now" weather_now bind pub - "!today" weather_today bind pub - "!monday" weather_monday bind pub - "!tuesday" weather_tuesday bind pub - "!wednesday" weather_wednesday bind pub - "!thursday" weather_thursday bind pub - "!friday" weather_friday bind pub - "!saturday" weather_saturday bind pub - "!sunday" weather_sunday # Define the procedures proc get_weather {url} { set token [http::geturl $url] set data [http::data $token] http::cleanup $token return $data } proc parse_weather {data} { set json_data [json::json2dict $data] set temperature [dict get $json_data temperature_2m] set description [dict get $json_data weathercode] set sunrise [dict get $json_data sunrise] set sunset [dict get $json_data sunset] set precipitation [dict get $json_data precipitation_sum] set wind_speed [dict get $json_data windspeed_10m_max] set wind_direction [dict get $json_data winddirection_10m_dominant] return "Temperature: $temperature°C\nDescription: $description\nSunrise: $sunrise\nSunset: $sunset\nPrecipitation: $precipitation mm\nWind Speed: $wind_speed km/h\nWind Direction: $wind_direction" } proc weather_now {nick host handle channel text} { set data [get_weather $::api_url] set response [parse_weather $data] putquick "PRIVMSG $channel :$response" } proc weather_today {nick host handle channel text} { set data [get_weather $::api_url] set json_data [json::json2dict $data] set forecast_data [dict get $json_data daily 0] set temperature_max [dict get $forecast_data temperature_2m_max] set temperature_min [dict get $forecast_data temperature_2m_min] set description [dict get $forecast_data weathercode] set response "Today's Forecast:\nMaximum Temperature: $temperature_max°C\nMinimum Temperature: $temperature_min°C\nDescription: $description" putquick "PRIVMSG $channel :$response" } proc weather_monday {nick host handle channel text} { # Get the forecast for Monday (index 1) set data [get_weather $::api_url] set json_data [json::json2dict $data] set forecast_data [dict get $json_data daily 1] # Parse the forecast data set temperature_max [dict get $forecast_data temperature_2m_max] set temperature_min [dict get $forecast_data temperature_2m_min] set description [dict get $forecast_data weathercode] # Construct and send the response message set response "Monday's Forecast:\nMaximum Temperature: ${temperature_max}°C\nMinimum Temperature: ${temperature_min}°C\nDescription: ${description}" putquick "PRIVMSG ${channel} :${response}" } # Define procedures for other days of the week in a similar way