AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 77 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6
Author Message
 Post subject:
PostPosted: June 28th, 2008, 3:45 am 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
This has been broken so long that I don't even remember what it's supposed to look like, but I know it's closer than it was before I started messing with it. I have modified the script so that it just reads the forecast without the other 'garbage', which looks fine when you click on it and it opens in a message box, but in the GUI the ForTx's are split like ''Tonight:'' in the first one, then the actual forecast for tonight in the next, then a line feed in the next, then ''Tomorrow:'' in the next, then the actual forecast for tomorrow in the next, and so on.

I could really use a hand because this type of code (RegEx, etcetera) is SOOOO not my strongest skill.

The only changes I've made have been in the Refresh() function (and maybe that's the problem). Further, I've made so many changes (and un-changes) that I've almost lost track of what I've twiddled with.

Anyway, I'll keep trying, but I'm about spent for tonight and thought I'd post what I've done so far (only posted the function)... Maybe someone will have some suggestions.

Code:
Refresh() {
   SetBatchLines, -1
   global temp, forecast, batchlines
   GuiControl, Disable, ForUD
   Set("Title", "Loading Weather...")
   Set("Sub", "...")
   Set("ForT", "Loading Weather...")
   Set("ForTx", "...")
   Menu, Tray, Tip, Loading Weather...
   SB_SetText("Loading...")
   url := Get("SetLoc")
   StringMid, url, url, InStr(url, "(") + 1, InStr(url, ")") - InStr(url, "(") - 1
   url := "http://xml.weather.yahoo.com/forecastrss?prevcache=" . A_Now . "&p=" . url
   If Get("SetTempC")
      url = %url%&u=c
   Else url = %url%&u=f
   file = ~wthr%A_Now%.tmp
   URLDownloadToFile, %url%, %file%
   If XMLRead(file, "rss", "attribute('xmlns:yweather')") != "http://xml.weather.yahoo.com/ns/rss/1.0" {
      MsgBox, 16, Error, The specified Yahoo! country code seems to be invalid or there has been an error with downloading.
      Return
   }
   Set("Title", XMLRead(file, "rss.channel.yweather:location", "attribute('city')") . " Weather")
   t1 := XMLRead(file, "rss.channel.yweather:wind", "attribute('chill')")
      . "°" . XMLRead(file, "rss.channel.yweather:units", "attribute('temperature')")
      . " - " . XMLRead(file, "rss.channel.item.yweather:condition", "attribute('text')")
   Set("Sub", t1 . " (High: " . XMLRead(file, "rss.channel.item.yweather:forecast", "attribute('high')")
      . "°" . XMLRead(file, "rss.channel.yweather:units", "attribute('temperature')")
      . " / Low: " XMLRead(file, "rss.channel.item.yweather:forecast", "attribute('low')")
      . "°" . XMLRead(file, "rss.channel.yweather:units", "attribute('temperature')") . ")")
   t := XMLRead(file, "rss.channel.item.title")
   StringReplace, t, t, Conditions for%A_Space%
   Set("ForT", t)
   Menu, Tray, Tip, % Get("ForT") . "`n" . t1
   t := XMLRead(file, "rss.channel.item.link")
   StringTrimLeft, t, t, InStr(t, "*")
   Icon(XMLRead(file, "rss.channel.item.yweather:condition", "attribute('code')"))
   URLDownloadToFile, %t%?preventcache=%A_Now%, %file%
   FileRead, s, %file%
   StringTrimLeft, forecast, s, InStr(s, "<h3>Detailed Local Forecast</h3>")
   ;StringTrimLeft, forecast, forecast, InStr(forecast, "<h3>Detailed Local Forecast</h3>")
   StringMid, forecast, forecast, InStr(forecast, "<li><strong>")
      , InStr(forecast, "</ul>") - InStr(forecast, "<li><strong>") - 1
   forecast := plaintxt(forecast)
   StringReplace, forecast, forecast, `r
   StringReplace, forecast, forecast, `n, `n, All UseErrorLevel ;Counts linefeeds, but not sure how that helps
   StringLeft, t, forecast, InStr(forecast, "`n") ;two `n ("`n`n") works for first ForTx, but then breaks
   GuiControl, % "+Range1-" . ErrorLevel + 1, ForUD
   GuiControlGet, tp, Pos, ForUD
   GuiControl, Move, ForUD, w%tpw%
   Set("ForTx", t)
   FileDelete, %file%
   FormatTime, t, , h:mm tt
   SB_SetText("Last Updated: " . t)
   GuiControl, Enable, ForUD
   SetBatchLines, %batchlines%
}

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2008, 2:23 pm 
Offline

Joined: April 25th, 2007, 10:13 pm
Posts: 29
How about this:

Code:
   forecast := plaintxt(forecast)

   forecast := RegExReplace(forecast, ":\s+", ": ")
   forecast := RegExReplace(forecast, "\r\n", "")


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 77 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, maul.esel and 8 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