Code: Select all
FormatTime, Month, , M
todaystr = %A_DDD% %A_DD%/%Month%:
tomorrowstr := TomorrowName() . " " . TomorrowDate() . ":"
Data := UpdateWeather()
tempnow := Data.current.temperature_2m Chr(0x00B0)
feelslike := Data.current.apparent_temperature Chr(0x00B0)
today_max := Chr(0x1F4C8) Data.daily.temperature_2m_max[1]
today_min := Chr(0x1F4C9) Data.daily.temperature_2m_min[1]
tomorrow_max := Chr(0x1F4C8) Data.daily.temperature_2m_max[2]
tomorrow_min := Chr(0x1F4C9) Data.daily.temperature_2m_min[2]
currentWeather := GetWeatherDescription(Data.current.weather_code)
nowimage := GetWeatherImage(Data.current.weather_code)
todaydesc := GetWeatherDescription(Data.Daily.weather_code[1])
todayimage := GetWeatherImage(Data.Daily.weather_code[1])
tomorrowdesc := GetWeatherDescription(Data.Daily.weather_code[2])
tomorrowimage := GetWeatherImage(Data.Daily.weather_code[2])
; daylightduration := "about " . Round(Data.Daily.daylight_duration[1] / 3600) . " hours of daylight tomorrow"
sunset := SubStr(Data.Daily.sunset[1], 12)
; cloudage := Data.current.cloud_cover . "%"
rainchancetoday := Data.Daily.precipitation_probability_max[1] . "%"
rainchancetomorrow := Data.Daily.precipitation_probability_max[2] . "%"
maxcolor := CheckColor(Data.daily.temperature_2m_max[1])
mincolor := CheckColor(Data.daily.temperature_2m_min[1])
tomorrowmaxcolor := CheckColor(Data.daily.temperature_2m_max[2])
tomorrowmincolor := CheckColor(Data.daily.temperature_2m_min[2])
nowcolor := CheckColor(Data.current.temperature_2m)
feelslikecolor := CheckColor(Data.current.apparent_temperature)
; If (Data.daily.temperature_2m_max[1] > 20)
; maxcolor = yellow
; Else
; maxcolor := "white" ;CheckColor(Data.daily.temperature_2m_max[1])
; If (Data.daily.temperature_2m_min[1] > 20)
; mincolor = yellow
; Else
; mincolor := "white" ;CheckColor(Data.daily.temperature_2m_max[1])
; If (Data.daily.temperature_2m_min[2] > 20)
; tomorrowmincolor = yellow
; Else
; tomorrowmincolor := "white" ;CheckColor(Data.daily.temperature_2m_max[1])
; If (Data.daily.temperature_2m_max[2] > 20)
; tomorrowmaxcolor = yellow
; Else
; tomorrowmaxcolor := "white"
weatherbackground := GetBackground(Data.current.weather_code)
Gui, TextGUI:Margin, 0, 0
Gui, TextGUI:+Border +Owner -Caption -MaximizeBox +AlwaysOnTop +Hwndtexthwnd +LastFound +ToolWindow +E0x20
Gui, TextGUI:Color, 131314
Gui, TextGUI:Font, S30 Q4, Leelawadee UI Semilight
Gui, TextGUI:Add, Text, vtempnow_id cYellow x0 y-10, %tempnow%
; Gui, TextGUI:Add, Picture, x0 y0 h50 w50 HWNDpic, D:\Autohotkey Scripts\weather icons\sunset.png
Gui, TextGUI:Font, S20 Q4, Leelawadee UI Semilight
Gui, TextGUI:Add, Text, vfeelslike_id cWhite x0 y35, Feels like %feelslike%
Gui, TextGUI:Font, S17 Q4, Leelawadee UI Semilight
Gui, TextGUI:Add, Text, vcurrentweather_id cWhite x150 y0, %currentWeather%
; Gui, TextGUI:Font, S16 Q4, Segoe UI
Gui, TextGUI:Add, Picture, x100 y90 h40 w40 HWNDtodayimage_id, %todayimage%
Gui, TextGUI:Add, Picture, x100 y145 h40 w40 HWNDtomorrowimage_id, %tomorrowimage%
Gui, TextGUI:Add, Picture, x100 y0 h40 w40 HWNDnowimage_id, %nowimage%
; Gui, TextGUI:Add, Picture, x0 y45 h25 w45, cloudy.png
; Gui, TextGUI:Add, Text, cWhite x55 y45 vcloudage_id, %cloudage%
; Gui, TextGUI:Add, Text, cWhite x0 y0 vcurrentWeather_id, %currentWeather%
;Gui, TextGUI:Add, Picture, x0 y0 h40 w40 HWNDpic, D:\Autohotkey Scripts\weather icons\sunset.png CONITINUE - ADD IMAGES
Gui, TextGUI:Add, Picture, x300 y40 h50 w50 HWNDpic, D:\Autohotkey Scripts\weather icons\sunset.png
Gui, TextGUI:Add, Text, cWhite x355 y45 vsunset_id, %sunset%
Gui, TextGUI:Add, Text, cWhite x0 y90 vtodaystr, %todaystr%
Gui, TextGUI:Add, Picture, x140 y90 h40 w35, rain chance.png
Gui, TextGUI:Add, Text, cWhite x180 y95 vrainchancetoday_id,%rainchancetoday%
Gui, TextGUI:Add, Text, c%maxcolor% x233 y90 vtoday_max_id, %today_max%
Gui, TextGUI:Add, Text, c%mincolor% x310 y90 vtoday_min_id, %today_min%
Gui, TextGUI:Add, Text, cWhite x0 y145 vtomorrow, %tomorrowstr%
Gui, TextGUI:Add, Picture, x140 y140 h40 w35, rain chance.png
Gui, TextGUI:Add, Text, cWhite x180 y145 vrainchancetomorrow_id, %rainchancetomorrow%
Gui, TextGUI:Add, Text, c%tomorrowmaxcolor% x233 y145 vtomorrow_max_id, %tomorrow_max%
Gui, TextGUI:Add, Text, c%tomorrowmincolor% x310 y145 vtomorrow_min_id, %tomorrow_min%
Gui, TextGUI:Show, x2540 y100 w430 h180 NA
WinSet, Transparent, 200
SetTimer, UpdateWidget, 600000
; SetTimer, UpdateWidget, 2000
Return
UpdateWidget:
prev_nowimage := GetWeatherImage(Data.current.weather_code)
prev_todayimage := GetWeatherImage(Data.Daily.weather_code[1])
prev_tomorrowimage := GetWeatherImage(Data.Daily.weather_code[2])
FileRead, yuh, D:\Autohotkey Scripts\Weather logs\Weather Monday 18.03.2024.json
Data := JSON.Load(yuh)
tempnow := Data.current.temperature_2m Chr(0x00B0)
feelslike := Data.current.apparent_temperature Chr(0x00B0)
today_max := Chr(0x1F4C8) Data.daily.temperature_2m_max[1]
today_min := Chr(0x1F4C9) Data.daily.temperature_2m_min[1]
tomorrow_max := Chr(0x1F4C8) Data.daily.temperature_2m_max[2]
tomorrow_min := Chr(0x1F4C9) Data.daily.temperature_2m_min[2]
currentWeather := GetWeatherDescription(Data.current.weather_code)
nowimage := GetWeatherImage(Data.current.weather_code)
todaydesc := GetWeatherDescription(Data.Daily.weather_code[1])
todayimage := GetWeatherImage(Data.Daily.weather_code[1])
tomorrowdesc := GetWeatherDescription(Data.Daily.weather_code[2])
tomorrowimage := GetWeatherImage(Data.Daily.weather_code[2])
; daylightduration := "about " . Round(Data.Daily.daylight_duration[1] / 3600) . " hours of daylight tomorrow"
sunset := SubStr(Data.Daily.sunset[1], 12)
; cloudage := Data.current.cloud_cover . "%"
rainchancetoday := Data.Daily.precipitation_probability_max[1] . "%"
rainchancetomorrow := Data.Daily.precipitation_probability_max[2] . "%"
maxcolor := CheckColor(Data.daily.temperature_2m_max[1])
mincolor := CheckColor(Data.daily.temperature_2m_min[1])
tomorrowmaxcolor := CheckColor(Data.daily.temperature_2m_max[2])
tomorrowmincolor := CheckColor(Data.daily.temperature_2m_min[2])
nowcolor := CheckColor(Data.current.temperature_2m)
feelslikecolor := CheckColor(Data.current.apparent_temperature)
if (prev_nowimage != nowimage) {
GuiControl, , %nowimage_id%, %nowimage%
}
if (prev_todayimage != todayimage) {
GuiControl, , %todayimage_id%, %todayimage%
}
if (prev_tomorrowimage != tomorrowimage) {
GuiControl, , %tomorrowimage_id%, %tomorrowimage%
}
GuiControl, TextGui:, tempnow_id, %tempnow%
GuiControl, TextGui:, feelslike_id, Feels like %feelslike%
GuiControl, TextGui:, currentWeather_id, %currentWeather%
GuiControl, TextGui:, sunset_id, %sunset%
GuiControl, TextGui:, rainchancetoday_id, %rainchancetoday%
GuiControl, TextGui:, cloudage_id, %cloudage%
GuiControl, TextGui:, today_max_id, %today_max%
GuiControl, TextGui:+c%maxcolor%, today_max_id
GuiControl, TextGui:, today_min_id, %today_min%
GuiControl, TextGui:+c%mincolor%, today_min_id
GuiControl, TextGui:, rainchancetomorrow, %rainchancetomorrow%
GuiControl, TextGui:, tomorrow_max_id, %tomorrow_max%
GuiControl, TextGui:+c%tomorrowmaxcolor%, tomorrow_max_id
GuiControl, TextGui:, tomorrow_min_id, %tomorrow_min%
GuiControl, TextGui:+c%tomorrowmincolor%, tomorrow_min_id
Return
Code: Select all
;Returns an object with the details of the weather
UpdateWeather()
{
link := "https://api.open-meteo.com/v1/forecast?¤t=temperature_2m,apparent_temperature,weather_code,cloud_cover&daily=weather_code,temperature_2m_max,temperature_2m_min,sunset,daylight_duration,precipitation_probability_max&timezone=auto&forecast_days=3&forecast_hours=6" ;"https://wttr.in/petah+tiqwa?format=%t"
FormatTime, Time,, dddd dd.MM.yyyy
UrlDownloadToFile, %link%, D:\Autohotkey Scripts\Weather logs\Weather %Time%.json
FileRead, yuh, D:\Autohotkey Scripts\Weather logs\Weather %Time%.json
yuh := JSON.Load(yuh)
Return yuh
}
; Returns the color based on the temperature
CheckColor(temp) {
if (temp >= 10 and temp < 15) {
return "White"
} else if (temp >= 15 and temp < 25) {
return "ffff14" ; bright yellow
} else if (temp >= 25 and temp < 30) {
return "d98a12"
} else if (temp >= 30 and temp < 50) {
return "Red"
} else {
return "White"
}
}
;Gets tomorrow's date
TomorrowDate(GetYear := False) {
today = %a_now%
today += +1, days
If (GetYear)
FormatTime, today, %today%, dd/M/yy
Else
FormatTime, today, %today%, dd/M
return today
}
;Gets tomorrow's name based on today
TomorrowName()
{
Switch A_DDD
{
case "Sun":
Return "Mon"
case "Mon":
Return "Tue"
case "Tue":
Return "Wed"
case "Wed":
Return "Thu"
case "Thu":
Return "Fri"
case "Fri":
Return "Sat"
case "Sat":
Return "Sun"
}
}
;Returns the rain chance in words
RainChance(rainchance) {
if (rainchance >= 0 and rainchance < 10) {
return "no chance"
} else if (rainchance >= 10 and rainchance < 30) {
return "low chance"
} else if (rainchance >= 30 and rainchance < 50) {
return "some chance"
} else if (rainchance >= 50 and rainchance < 70) {
return "moderate chance"
} else if (rainchance >= 70 and rainchance < 90) {
return "high chance"
} else if (rainchance >= 90 and rainchance <= 100) {
return "very high chance"
} else {
return "Invalid chance"
}
}
;Translates the cloud coverage % to a description
CloudCoverage(percentage) {
if (percentage >= 0 and percentage <= 15) {
return "Clear"
} else if (percentage > 15 and percentage <= 30) {
return "Partly Cloudy"
} else if (percentage > 30 and percentage <= 70) {
return "Cloudy"
} else if (percentage > 70 and percentage <= 100) {
return "Overcast"
} else {
return "Invalid percentage"
}
}
;Returns a corresponding image based on the weather code
GetWeatherImage(code) {
switch (code) {
case 0:
Image = clear.png
case 1, 2, 3:
Image = partly cloudy.png
case 45, 48:
Image = fog.png
case 51, 53, 55:
Image = rain.png
case 56, 57:
Image = rain.png
case 61, 63, 65:
Image = heavy rain.png
case 66, 67:
Image = thunderstorm.png
case 71, 73, 75:
Image = thunderstorm.png
case 77:
Image = thunderstorm.png
case 80, 81, 82:
Image = heavy rain.png
case 85, 86:
Image = thunderstorm.png
case 95:
Image = heavy rain.png
case 96, 99:
Image = thunderstorm.png
default:
return "Unknown code"
}
Return Image
}
;Returns a description of the weather by its weather code (WMC)
GetWeatherDescription(code) {
switch (code) {
case 0:
return "Clear skies"
case 1, 2, 3:
return "Mainly clear, partly cloudy"
case 45, 48:
return "Foggy"
case 51, 53, 55:
return "Drizzle: Light intensity"
case 56, 57:
return "Freezing Drizzle: Light intensity"
case 61, 63, 65:
return "Rainy: Moderate intensity"
case 66, 67:
return "Freezing Rain: Heavy intensity"
case 71, 73, 75:
return "Snow fall: Slight intensity"
case 77:
return "Snow grains"
case 80, 81, 82:
return "Rain showers: Violent"
case 85, 86:
return "Snow showers slight and heavy"
case 95:
return "Slight thunderstorm"
case 96, 99:
return "Thunderstorm with slight and heavy hail"
default:
return "Unknown code"
}
}