/*
=== Weather gadget
● top left circle - toggle always on top
● double click on the title to go to the saved position
● F4 - show GUI , or click on tray icon
● more options in the right click context menu: background color; save position for next launch,
● Accuweather forecast in popup window
● Depending on a country, data is received in Fahrenheit or Celsius degrees.
So choose units below: unit:="C" or unit:="F".
Convert Fahrenheit to Celsius with option: F_to_Celsius:=1
● To start not on top of other windows: enable this line #227 ;Gosub, onTop
*/
;==========
;weather_url:="https://www.accuweather.com/en/it/rome/213490/current-weather/213490"
;weather_url:="https://www.accuweather.com/en/pl/krakow/274455/current-weather/274455"
weather_url:="https://www.accuweather.com/en/us/new-york-ny/10007/current-weather/349727#"
;==========
;unit:="C" ; if data received in Celsius degrees (in a particular country)
unit:="F" ; if data received in Fahrenheit (in a particular country)
F_to_Celsius:=0 ; convert fahrenheit to Celsius if data received in Fahrenheit
;==========
write_ini:=0 ; stores data for 1 month
#SingleInstance force
#NoEnv
;#NoTrayIcon
Menu, Tray, Add , Weather , weather
Menu, Tray, Add ,
;Menu, Tray, Icon, shell32.dll,14 ; 47 ; ; 95 ;22
Menu, Tray, Icon, netshell.dll, 86
Menu, Tray, Add , Edit Scite, Edit_Scite
Menu, Tray, Add , Edit Notepad, Edit_Notepad
Menu, Tray, Add, Exit , Exit ; double click tray icon to exit
Menu, Tray, Default, Exit
Menu, ContextMenu, Add, On Top, OnTop
;Menu, ContextMenu, Icon, On Top, Shell32.dll, 147
Menu, ContextMenu, Icon, On Top, Shell32.dll, 248 ;wmploc.dll, 17
Menu, ContextMenu, Add, Save current position , save_position
Menu, ContextMenu, Icon, Save current position , Shell32.dll,124 ; 268 ;101 124
Menu, ContextMenu, Add,
Menu, Submenu1, Add, Black , set_bgrd_black
Menu, Submenu1, Add, Steel , set_bgrd_steel
Menu, Submenu1, Add, Blue , set_bgrd_blue
Menu, Submenu1, Add, Green , set_bgrd_green
;Menu, Submenu1, Add,
;Menu, Submenu1, Add, Funny style: dots, set_bgrd_style_dots
;Menu, Submenu1, Add, Funny style: dots 2, set_bgrd_style_dots2
;Menu, Submenu1, Add, Funny style: bricks, set_bgrd_style_bricks
;Menu, Submenu1, Add,
;Menu, Submenu1, Add, Reset background, reset_bgrd
Menu, ContextMenu, Add, Background color, :Submenu1
Menu, ContextMenu, Add,
Menu, ContextMenu, Add , Open settings file , Open_ini
Menu, ContextMenu, Icon , Open settings file , Shell32.dll, 70
;Menu, ContextMenu, Add , Open log , Open_log
Menu, ContextMenu, Add,
Menu, ContextMenu, Add , Go to website , Go_to_web
;Menu, ContextMenu, Icon , Go to website , C:Program FilesInternet Exploreriexplore.exe
Menu, ContextMenu, Icon , Go to website , shell32.dll, 221
Menu, ContextMenu, Add,
Menu, ContextMenu, Add , Forecast , Show_in_popup
;Menu, ContextMenu, Icon , Forecast , C:Program FilesInternet Exploreriexplore.exe
Menu, ContextMenu, Icon , Forecast , shell32.dll, 143 ;243
Menu, ContextMenu, Add,
Menu, ContextMenu, Add , Weather , weather
Menu, ContextMenu, Add ,
Menu, ContextMenu, Add, Restart, Reload
Menu, ContextMenu, Add, Exit, Exit
FileEncoding, UTF-8
SetWorkingDir %A_ScriptDir%
global settings_ini := "Drozd Weather.ini"
/* global log_file := "TempTemperatures_log_AHK.txt"
global reg_log_temp := "Tempreg_Temp_log_AHK.txt"
IfNotExist Temp
FileCreateDir, Temp
FileAppend, Temperature log`n , %reg_log_temp%
*/
bgrd_grad_black:="0xff222222|0xff0F0F0F|33"
bgrd_grad_steel:="0xff1A2333|0xff2C3B54|33"
bgrd_grad_blue:="0xff06213D|0xff133557|33"
bgrd_grad_green:="0xff00230A|0xff044016|33"
bgrd_grad:=bgrd_grad_green ;bgrd_grad_black
bgrd_ramki_black:="0xff353535|0xff1C1C1C"
bgrd_ramki_steel:="0xff2D3F5D|0xff1A2333"
bgrd_ramki_blue:="0xff16416B|0xff0D263E"
bgrd_ramki_green:="0xff044016|0xff00230A"
bgrd_ramki:=bgrd_ramki_green ;bgrd_ramki_black
If !pToken := Gdip_Startup(){
MsgBox, 48, No Gdiplus
ExitApp
}
OnExit, Exit
SysGet, MonitorWorkArea, MonitorWorkArea, 1
pos_x:=A_ScreenWidth - 138
pos_y:= MonitorWorkAreaBottom -688
IniRead, read_, %settings_ini%, Weather, weather url
if(read_="ERROR" || read_=""){
IniWrite, %weather_url% , %settings_ini%, Weather, weather url
}else{
weather_url:=read_
}
IniRead, pos_x_saved, %settings_ini%, window position, x
IniRead, pos_y_saved, %settings_ini%, window position, y
if(!pos_x_saved || !pos_y_saved || pos_x_saved=="ERROR" || pos_y_saved=="ERROR"){
IniWrite, %pos_x% , %settings_ini%, window position, x
IniWrite, %pos_y% , %settings_ini%, window position, y
}else{
if(pos_x_saved", today )
;MsgBox,,, % today
RegExMatch(today,"im)Dew Point: (d+)° F",dew )
RegExMatch(today,"im)Now | s*(d+)° | ",temper )
RegExMatch(today,"im)(.*?)",cond )
RegExMatch(today,"im)
Humidity: (d+%)",Humid )
RegExMatch(today,"im)(.*?)",cond )
RegExMatch(today,"im)
Yesterday | s*
(d+)° | ",yesterday )
tem:=temper1
if tem is not integer
{
MsgBox,,Drozd Weather, % "Temperature read error.`nWill check again in 1 min." , 3
SetTimer, check_again, -60000
return
}
dew:=dew1
yester:=yesterday1
if(F_to_Celsius){
tem:=f_C(tem) Chr(176) "C" ;"°C"
dew:=f_C(dew) Chr(176) "C" ;"°C"
yester:=f_C(yester) Chr(176) "C" ;"°C"
}else{
tem:=tem Chr(176) unit ;"°"
dew:=dew Chr(176) unit ;"°"
yester:=yester Chr(176) unit ;"°"
}
hum:=Humid1
last_temp:=tem
strT:=" Temperature: " tem " "
strD:=" Dew point: " dew " "
strH:=" Humidity: " Humid1 " "
strY:=" Yesterday: " yester
tray_tip:=" " cond1 "`n" strT "`n" strD "`n" strH "`n" strY
strT_:=" Temperature: " tem " (" temper1 "F)" " "
strD_:=" Dew point: " dew " (" dew1 "F)" " "
strH_:=" Humidity: " Humid1 " "
strY_:=" Yesterday: " yester " (" yesterday1 "F)"
tray_tipC_F:=" " cond1 "`n" strT_ "`n" strD_ "`n" strH_ "`n" strY_
tray_tip:=(F_to_Celsius==1) ? tray_tipC_F : tray_tip
GuiControl,, Tem, %tem%
GuiControl,, Hum, %hum%
GuiControl,, Dew, %dew%
GuiControl,, Con, %cond1%
FormatTime, date, %A_Now%, HH:mm MMMd
GuiControl,, last_check, %date%
SetTimer, hide_time, -3000
return
write_:
if(write_ini!=1)
return
IniRead, today_1, %settings_ini%, % A_MM " " A_YYYY , % A_MMM A_DD
IniRead, reg_log_, %settings_ini%, % A_MM " " A_YYYY , % A_MMM A_DD
reg_log_:=(reg_log_=="ERROR") ? "" : reg_log_ " | "
reg_log:= A_Hour "h " tem
reg_log:=reg_log_ reg_log
if !InStr(reg_log_,A_Hour "h")
IniWrite, %reg_log% , %settings_ini%, % A_MM " " A_YYYY, % A_MMM A_DD
return
hide_time:
SetTimer, hide_time, Off
GuiControl, Hide, last_check
return
check_again:
Gosub, weather
return
f_C(t,d:=0){ ;(°F - 32) x 5/9 = °C ;fahrenheit_to_celsius
t:= (t-32)*(5/9)
t:=Round(t,d)
return t
}
;======================
del_last_month(){
global reg_log_temp
prev_m:= (A_MM!=01) ? dig(A_MM - 1) " " A_YYYY : 12 " " A_YYYY-1
IniRead, prev_month , %settings_ini%, % prev_m
if(prev_month!=""){
if FileExist(reg_log_temp){
FileAppend, `n%prev_m%`n , %reg_log_temp%
FileAppend, %prev_month%`n , %reg_log_temp%
}
IniDelete, %settings_ini%, %prev_m%
}
; leftovers
Loop % A_MM-1 {
prev_m:=dig(A_MM-A_Index) " " A_YYYY
IniRead, prev_month , %settings_ini%, % prev_m
if(prev_month!=""){
IniDelete, %settings_ini%, %prev_m%
}
}
}
dig(num){ ;to_two_digits
num:= numCeiling:
(d+) ftCeiling: (d+) ftVisibility: (d+) mi", match)){
match:=RegExReplace(match,match1 " mi", mile_to_km(match1))
HTML_page:=RegExReplace(HTML_page,"im)Visibility: (d+) mi", match)
}
if(RegExMatch(HTML_page,"i)(d+) mph(d+) mphs+([sS]*Next 5 Days[sS]*)
",Next_5_Days)
RegExMatch(HTML_page,"ims)s+(
.*Next 5 Days.*?)(?=
)",Next_5_Days)
HTML_page1 =
( comments
Forecast
; TEST
)
HTML_page:= HTML_page1 Next_5_Days1 "" weather_url "
" "