|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Tue Aug 31, 2010 1:22 pm
[3.24]Bug with <image>? |
I posted it here, but decided I should write a separate post anyway.
My script used to work flawlessly. I have stored images to display when needed. It's for displaying my local weather in a small window.
It no longer displays an image. Where:
Code: |
zs.mxp("<image ./Images/" .. image .. ".gif>") (essentially #MXP {<image %concat("./Images/",%param(1),".gif")>}) |
used to work, now it attempts to download the image file but never displays it. Even adding 'type' to it didn't seem to make it work.
I'm guessing this has something to do with the recent change regarding 'type' addition.
Charneus |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Tue Aug 31, 2010 1:27 pm |
Oh, and for those interested in the script:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<alias name="showlocalweather" language="Lua" copy="yes">
<value><![CDATA[if not http then http = require("socket.http") end
local locale = string.gsub(zs.params(1),"%s+","%%20")
local page = http.request("http://www.wunderground.com/cgi-bin/findweather/getForecast?query=" .. locale .. "&wuSelect=WEATHER")
local localtime = string.match(page,'Local Time:%c+<span class="b">([%d%s%w:,]+)</span>')
local location = string.match(page,'title="([%w%s,]+) RSS"')
local image, condition = string.match(page, '<td class="vaM taC"><img src="http.+/([%w_]+)%.gif" width="42" height="42" alt="([%w%s]+)" class="condIcon" />')
local temperature = string.match(page,'pwsvariable="tempf" english="°F" metric="°C" value="([%d.]+)">')
local humidity = string.match(page,'pwsvariable="humidity" english="" metric="" value="(%d+)"')
zs.say(location)
zs.mxp("<image ./Images/" .. image .. ".gif>")
zs.say("<color limegreen>Condition:</color> <color white>" .. condition .. "</color>")
zs.say("<color limegreen>Temperature: </color><color white>" .. temperature .. "F</color>")
zs.say("<color limegreen>Humidity: </color><color white>" .. humidity .. "%</color>")
zs.say("<color limegreen>Last update: </color><color white>" .. string.gsub(localtime," on %w+ %d+, %d+","") .. "</color>")]]></value>
</alias>
</cmud> |
What I did was go to wunderground.com and save all their icons (and new ones as they came along). Just do 'showlocalweather "City, State"' (can do it by airport code or city/country too).
Charneus |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Aug 31, 2010 4:45 pm |
Posted in the other thread about adding this to bug list.
But I had to post again here just to say: COOL! What a great script!
I'd be interested in seeing a version for CMUDPro that uses the new %url function instead of the Lua http stuff. |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Tue Aug 31, 2010 6:27 pm |
I'll second that. Very nice Charneus.
|
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Tue Aug 31, 2010 11:00 pm |
Zugg wrote: |
Posted in the other thread about adding this to bug list.
But I had to post again here just to say: COOL! What a great script!
I'd be interested in seeing a version for CMUDPro that uses the new %url function instead of the Lua http stuff. |
If I had documentation for %url, I'd be glad to look into it and see what I can do.
Charneus |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Sep 01, 2010 4:32 pm |
It was linked in the Version History and is here: zApp URL object
The %url function creates a zApp URL COM object. So you use it like this:
Code: |
u = %url("www.whatever.com")
#SHOW @u.Get |
The difference between %url in CMUD and URL in zApp is that any function that required a url string in zApp doesn't need it in CMUD because in CMUD the url string is specified when you create the object using %url. Also, the Params and PostParams functions are a bit different. In CMUD they act somewhat like database variables. For example:
Code: |
u = %url("http://www.whatever.com/script.php?arg=value")
#SHOW @u.Params.arg // displays "value" |
So to send POST arguments, you can do this:
Code: |
u = %url("www.whatever.com")
u.PostParams.arg = "value"
#SHOW @u.Post |
So, in your script it would be something like this:
Code: |
u = %url( "http://www.wunderground.com/cgi-bin/findweather/getForecast")
u.Params.query = $locale
u.Params.wuSelect = "WEATHER"
page = @u.Get
... |
Play around with it and see how it works. You might need to mess with it a bit, but that should give the general idea. |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Thu Sep 02, 2010 8:49 am |
NOTE: For CMUDPro users only! See above for a version for CMUD
Well, this was easier than I had anticipated.
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<alias name="getweather" copy="yes">
<value><![CDATA[$locale=%replace(%1, " ", "%20")
$u=%url(%concat("http://www.wunderground.com/cgi-bin/findweather/getForecast?query=",$locale,"&wuSelect=WEATHER"))
$page=$u.Get
#CALL %regex($page,"Local time:\n(?:.+)?<span class=""b"">(\d+:\d+ (?:AM|PM) \w{3})</span>",$LocalTime)
#CALL %regex($page,"<title>([\w, ]+)(?:.+)?Forecast(?:.+)?</title>",$Location)
#CALL %regex($page,"<td class=""vaM taC""><img src=""http.+/([\w_]+).gif"" width=""42"" height=""42"" alt=""([\w\s]+)"" class=""condIcon"" />",$Image,$Condition)
#CALL %regex($page,"pwsvariable=""tempf"" english=""°F"" metric=""°C"" value=""([\d.]+)"">",$DegreeF)
#CALL %regex($page,"pwsvariable=""humidity"" english="""" metric="""" value=""(\d+)""",$Humidity)
$Image=%concat("./Images/",$Image,".gif")
#SAY {%ansi(high,green)$Location %ansi(white)($LocalTime)}
#MXP {<image $Image>}
#SAY {%ansi(high,green)Condition: %ansi(white)$Condition}
#SAY {%ansi(high,green)Temperature: %ansi(white)%concat($DegreeF,"F")}
#SAY {%ansi(high,green)Humidity: %ansi(white)%concat($Humidity,"%")}]]></value>
</alias>
</cmud>
|
The /only/ thing I can't seem to get to work is the Images, though it reports it correctly. You can mess around with that as you like. It may just be a small step that I'm missing. The ./Images/ directory is in my My Documents\CMUD\ folder, by the way. I forgot where I got the icons from because I know I didn't download them individual as they came up weather-wise, so I've gone ahead and made a zip file of all my icons for your use. The zip file can be downloaded from Charneus's Weather Icons (If link doesn't work for you, try clicking it again. If not, then right-click and use 'Save as'. Otherwise, type the link directly in your browser bar).
The syntax is simply:
Code: |
getweather "<param>" |
where <param> can be city/state, city/country, zip code, or [even airport terminal code. If you have any questions, don't hesitate to ask. It's a fun script, if nothing else. I use it on Aardwolf, and have set up a bot so people can just type 'melvin, get weather for 12345' and it'll return the information. Also grabs definitions from urban dictionary (can use any dictionary, really), does spell checks, and pretty soon, will probably be able to report scores for various teams. Yes, I'm that bored sometimes.
Charneus |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Sep 02, 2010 4:41 pm |
Are you saying that v3.25 still doesn't handle the relative path for the Image?
If not, also try:
Code: |
<IMAGE ".\Images\filename.gif"> |
since Windows probably wants the proper \ character for the path instead of /. I think CMUD takes care of this conversion, so it might have the same problem, but it's worth a try. I'll also play with it more here. |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Thu Sep 02, 2010 10:14 pm |
As far as my lua script goes, 3.25 is handling relative paths easily.
As far as this script goes (and it may just be Pro), nothing I've tried works.
I've tried:
Code: |
./Images/$Image.gif
%concat("./Images/",$Image,".gif")
.\Images\$Image.gif
%concat(".\Images\",$Image,".gif")
%concat("C:\Users\Charneus\My Documents\My Games\CMUD\Images\",$Image,".gif") |
None of these worked. Since I don't use CMUDPro (I've considered it in the past, but just haven't, yet), I couldn't tell you if it is a bug or not with just Pro. However, considering that any one of those above works on non-Pro version. Further testing shows that it's producing the proper path name, it's just not displaying the image. If you'd like, I could make this a completely separate topic (scripts and all).
Charneus |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Sep 03, 2010 4:53 pm |
That's ok, it's on my bug list to look at. The code that fixed problems with invalid characters in a image URL/filename still seems to be screwing up relative path links.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Sep 10, 2010 10:39 pm |
Here is what I just tried:
Code: |
$image="testimage";#MXP <IMAGE %concat("./Images/",$Image,".gif")> |
This worked fine in v3.25.
Remember that if you have $image within any " quotes, then it won't expand the variable.
Also, using $image.gif is being treated as a database lookup of the "gif" key in the $image variable. So you'll need to use %concat in this case. But %concat seems to work fine for me here. |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Fri Sep 10, 2010 11:30 pm |
So %url is only for CMUDPro? So tempted...
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Sep 11, 2010 12:08 am |
Correct.
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Thu Mar 17, 2011 1:30 pm |
Hmm... did you ever get the pro version to display all the data as the lua one?
All it returned for me was the temperature and humidity when i paste the XML into a blank alias. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Thu Mar 17, 2011 4:13 pm |
The webpage changed its format slightly. At the time the code was written, it returned everything correctly. If you view the source for the webpage, you might be able to figure out what needs to be changed, however. I just LOVE it when a webpage changes format on you. :P
|
|
|
|
edb6377 Magician
Joined: 29 Nov 2005 Posts: 482
|
Posted: Sat Jan 28, 2012 6:09 am This should work |
This one should work in general. Just remove the switches you don't want :)
Code: |
#SWITCH (%lower(%1)) ("clan") {
$locale=%replace(%-2," ", "%20")
$u=%url(%concat("http://www.wunderground.com/cgi-bin/findweather/getForecast?query=",$locale,"&wuSelect=WEATHER"))
$page=$u.Get
#CALL %regex($page,"<div id=""infoTime""><span>(\d+:\d+ (?:AM|PM) \w{3})",$LocalTime)
#CALL %regex($page,"<title>(?:.+)?Forecast ([\w, ]+)(?:.+)?</title>",$Location)
#CALL %regex($page,"class=""iconSwitchBig""><img src=""http.+/([\w_]+).gif"" width=""44"" height=""44"" alt=""([\w\s]+)"" class=""condIcon"" />",$Image,$Condition)
#CALL %regex($page,"pwsvariable=""tempf"" english=""°F"" metric=""°C"" value=""([\d.]+)"">",$DegreeF)
#SEND {"CT |GWeather: |W"$Location" Time:"$LocalTime" "$Condition" Temp:"$DegreeF"F"}
}
("off") {#T- ClanBot|Weather}
("on") {#SEND "CT |RError - WEATHER MODULE IS ALREADY ON|x"}
("") {#SAY %ansi(high,red)Examples of Valid Types: %ansi(white)city, state or city, country or zipcode or airport terminal}
{
$locale=%replace(%replace(%-1," ", "%20"),",","%2C")
$u=%url(%concat("http://www.wunderground.com/cgi-bin/findweather/getForecast?query="$locale))
$page=$u.Get
#CALL %regex($page,"<div id=""infoTime""><span>(\d+:\d+ (?:AM|PM) \w{3})",$LocalTime)
#CALL %regex($page,"<title>(?:.+)?Forecast ([\w, ]+)(?:.+)?</title>",$Location)
#CALL %regex($page,"class=""iconSwitchBig""><img src=""http.+/([\w_]+).gif"" width=""44"" height=""44"" alt=""([\w\s]+)"" class=""condIcon"" />",$Image,$Condition)
#CALL %regex($page,"pwsvariable=""tempf"" english=""°F"" metric=""°C"" value=""([\d.]+)"">",$DegreeF)
#CALL %regex($page,"pwsvariable=""humidity"" english="""" metric="""" value=""(\d+)""",$Humidity)
$Image=%concat($Image,".gif")
#SAY {%ansi(high,cyan)$Location %ansi(white)($LocalTime)}
#MXP <image $Image URL="http://icons-ak.wxug.com/i/c/k/">
#SAY {%ansi(high,green)Condition: %ansi(white)$Condition}
#SAY {%ansi(high,green)Temperature: %ansi(white)%concat($DegreeF,"F")}
#SAY {%ansi(high,green)Humidity: %ansi(white)%concat($Humidity,"%")}
}
|
|
|
_________________ Confucious say "Bugs in Programs need Hammer" |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|