AutoHotkey Community

It is currently May 27th, 2012, 12:07 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Simple Weather
PostPosted: March 1st, 2011, 8:35 pm 
Offline

Joined: May 15th, 2007, 8:59 pm
Posts: 169
I know there are plenty of more advanced weather apps made, but I wanted just a simple little weather script to add to some of my scripts.

You are free to fix or manipulate this code anyway you see fit. Enjoy.

It pulls the weather information from Googles open weather API.
It is currently set to update the weather from the US zipcode 57186 every 5 minutes (300 seconds) in fahrenheit.


Image



Code:
zipcode=57186      ;change 57186 to your zip code
updateseconds=300   ;Set Seconds between updates.

gui, add, Picture, vcurtemppic w30 h30
gui, add, text, vcurtemp w70 h30 x+5
gui, show

;update and set timer.
Gosub, updateweather
updateseconds:=updateseconds*1000 ;Convert to milliseconds
SetTimer, updateweather, %updateseconds%
Return


updateweather:
URLDownloadToFile, http://www.google.com/ig/api?weather=%zipcode%, weather.htm
FileRead, weatherxml, weather.htm
FileDelete, weather.htm

forcasthit=
loop, parse, weatherxml, `>`<
{
   ;Get Weather Image
      IfInString, a_loopfield, forecast_conditions
         forcasthit=1
      
      if (!forcasthit)
         {
            ;Get Temp in F
            IfInString, a_loopfield, temp`_f
               {
                  StringGetPos, quotestart, a_loopfield, `", L1
                  quotestart+=2
                  StringGetPos, quoteend, a_loopfield, `", L2
                  quoteend++

                  quotelen:=quoteend-quotestart
                  StringMid, curtemp, a_loopfield, quotestart, %quotelen%
                  GuiControl,,curtemp,%curtemp%°F`n%curcondition%
               }
            ;Get condition
            IfNotInString, a_loopfield, wind_condition data
               {
                  IfInString, a_loopfield, condition data
                     {
                        StringGetPos, quotestart, a_loopfield, `", L1
                        quotestart+=2
                        StringGetPos, quoteend, a_loopfield, `", L2
                        quoteend++

                        quotelen:=quoteend-quotestart
                        StringMid, curcondition, a_loopfield, quotestart, %quotelen%
                        GuiControl,,curtemp,%curtemp%°F`n%curcondition%
                     }
               }
            
            IfInString, a_loopfield, icon data
               {
                  StringGetPos, quotestart, a_loopfield, `", L1
                  quotestart+=2
                  StringGetPos, quoteend, a_loopfield, `", L2
                  quoteend++

                  quotelen:=quoteend-quotestart
                  StringMid, curtempimg, a_loopfield, quotestart, %quotelen%
                  curtempimg= http`:`/`/www.google.com%curtempimg%
                  URLDownloadToFile, %curtempimg%, curweather.jpg
                  GuiControl,,curtemppic,curweather.jpg
                  FileDelete, curweather.jpg
               }
         }
}
Return

GuiClose:
ExitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 2nd, 2011, 4:06 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
Frankly, I love it.
Thanks.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 3rd, 2011, 2:51 am 
Offline

Joined: January 26th, 2009, 5:26 pm
Posts: 151
You inspired me to make this:
Image
From here: http://www.wunderground.com/stickers/
into a persistent updating object on my screen using this code:
Code:
airportcode=KSFO      ;change to your nearest airport code
updateseconds=300   ;Set Seconds between updates.

Gui +Owner
Gui, Color, 000000
Gui, add, Picture, vcurtemppic gOpenURL w160 h90
Gui, show
Gui +LastFound
WinSet, TransColor, 000000
Gui -Caption +AlwaysOnTop

;update and set timer.
Gosub, updateweather
updateseconds:=updateseconds*1000 ;Convert to milliseconds
SetTimer, updateweather, %updateseconds%
Return


updateweather:
URLDownloadToFile, http://weathersticker.wunderground.com/weathersticker/cgi-bin/banner/ban/wxBanner?bannertype=wu_bluestripes&airportcode=%airportcode%, curweather.jpg
   GuiControl,,curtemppic,curweather.jpg
   FileDelete, curweather.jpg
Return

OpenURL:
GetKeyState, state, Shift
if state = D
   Run, http://www.wunderground.com/cgi-bin/findweather/hdfForecast?query=%airportcode%
Else
   PostMessage, 0xA1, 2
Return

GuiClose:
ExitApp


Last edited by LiquidGravity on March 3rd, 2011, 3:01 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 3rd, 2011, 2:55 am 
Offline
User avatar

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
Nice ones :)

Not that I liked Windows 7 gadgets, or Gadget-wannabes (that always stick around). But adding stuff like that to GUIs when needed could sure be useful. Might make an "on-demand" weather display based on yours, that only shows "right now". So you can check which coat to use before you go out. (You do go out, rite??).

Need to learn how to skin GUIs too.

_________________
~sumon Appifyer AHK Nova halted Recommended: AHK_L (Why?)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 3rd, 2011, 8:11 am 
Offline

Joined: February 3rd, 2010, 12:47 pm
Posts: 38
Location: Zagreb, Croatia
You may check this as well:
http://www.autohotkey.com/forum/viewtopic.php?t=58716&postdays=0&postorder=asc&start=0
BR


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2011, 8:57 am 
Offline

Joined: March 7th, 2011, 2:59 am
Posts: 151
Another nugget for the minimalists (currently resides on my Start Menu). :D


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: notsoobvious and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group