Advertisement
anonymous1184

Weather.ahk

Nov 4th, 2021 (edited)
916
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Warn
  2.  
  3. active := 0
  4.  
  5. return ; End of auto-execute
  6.  
  7. F12::ShowWeather()
  8.  
  9. F11::
  10.     active ^= 1
  11.     SetTimer CheckWeather, % active ? 1000 * 60 * 30 : "Delete"
  12.     if (active)
  13.         CheckWeather()
  14.     else
  15.         SetWallpaper("master")
  16. return
  17.  
  18. ShowWeather()
  19. {
  20.     FileRead zipCode, % A_ScriptDir "\zipcode.txt"
  21.     if (zipCode)
  22.         MsgBox % GetWeather(zipCode)
  23. }
  24.  
  25. CheckWeather()
  26. {
  27.     static zipCode := ""
  28.  
  29.     if !zipCode && !FileExist(A_ScriptDir "\zipcode.txt")
  30.     {
  31.         InputBox zipCode, Enter your zip code,,, 200, 100,,, Locale
  32.         if (!zipCode)
  33.         {
  34.             MsgBox 0x10, Error, Zip code is required.
  35.             ExitApp
  36.         }
  37.         FileOpen(A_ScriptDir "\zipcode.txt", 0x1).Write(zipCode)
  38.     }
  39.     weather := GetWeather(zipCode)
  40.     SetWallpaper(weather)
  41. }
  42.  
  43. GetWeather(ZipCode)
  44. {
  45.     url := "http://wttr.in/" ZipCode "?format=%C"
  46.     whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
  47.     whr.Open("GET", url, false)
  48.     whr.Send()
  49.     return whr.ResponseText
  50. }
  51.  
  52. SetWallpaper(Name)
  53. {
  54.     file := A_ScriptDir "\Wallpapers\" Name ".png"
  55.     if !FileExist(file)
  56.         return
  57.     DllCall("User32\SystemParametersInfo"
  58.         , "Int",0x0014
  59.         , "Int",0
  60.         , "Str",file
  61.         , "Int",0x2)
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement