Found it....
There are two kinds of "escape" chars and requirements involved here.
First, and as you have done, you need to escape the quote char, as it confuses Lua about what is literal, and what is the beginning and end of "strings".
THAT is a function of Lua in general. It's just what you need to do to use quotes as literals in strings. Use "\" for that.
Now... string.match has a few "reserved characters" just like Regular Expression does. They are:
( ) . % + - * ? [ ] ^ $
To "escape" these in a string.match, you need to use NOT the "\" char, but the "%" (percent) char.
From Programming in Lua - Second Ed:
The character `%' works as an escape for these magic characters. So, `%.' matches a dot; `%%' matches the character `%' itself. You can use the escape `%' not only for the magic characters, but also for all other non-alphanumeric characters. When in doubt, play safe and put an escape.
Started working after I went through and escaped stuff like:
.-onmouseup=\"trackLink('View Details: (.-)'
As
.-onmouseup=\"trackLink%('View Details: (.-)'
Having said that, it is very ugly indeed that a simple failure of a string.match function brought Rainmeter to its knees. For some reason the Lua just got in an endless loop, that was sucking all the oxygen that Rainmeter needed. It wasn't "hung" so much as "waiting".
It is currently April 28th, 2024, 5:48 am
Parsing troubles
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
-
- Posts: 7
- Joined: February 21st, 2011, 11:25 pm
Re: Parsing troubles
Perfect! Thank you so much jsmorely
I do have another question now though As you can see on the page I'm parsing, each item has an image, now I've grabbed the URLs and I'm attempting to use another WebParser measure to download them through a variable and then use an Image meter to display. But I can't seem to get it to work, a static url works fine, but trying to use a variable one just ends up with The Url is empty being printed to the log file over and over, even if the script as executed alright. Any more insight for me?
I do have another question now though As you can see on the page I'm parsing, each item has an image, now I've grabbed the URLs and I'm attempting to use another WebParser measure to download them through a variable and then use an Image meter to display. But I can't seem to get it to work, a static url works fine, but trying to use a variable one just ends up with The Url is empty being printed to the log file over and over, even if the script as executed alright. Any more insight for me?
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Parsing troubles
Can you post your skin and lua again so I can start from where you are?Ali1331 wrote:Perfect! Thank you so much jsmorely
I do have another question now though As you can see on the page I'm parsing, each item has an image, now I've grabbed the URLs and I'm attempting to use another WebParser measure to download them through a variable and then use an Image meter to display. But I can't seem to get it to work, a static url works fine, but trying to use a variable one just ends up with The Url is empty being printed to the log file over and over, even if the script as executed alright. Any more insight for me?
-
- Posts: 7
- Joined: February 21st, 2011, 11:25 pm
Re: Parsing troubles
The image links differ between items, some are relative and some are direct so that's why the if in the for loop is there.
Also, in my previous version I had channel captures as well, but when I tried putting Image capture in Lua error saying the statement was too complex, I guess 160 return values is too much
Lua
INI
I don't really know about the DynamicVariables stuff so I just kinda added it in hope.
Also, in my previous version I had channel captures as well, but when I tried putting Image capture in Lua error saying the statement was too complex, I guess 160 return values is too much
Lua
Code: Select all
PROPERTIES =
{
FileToParse = "";
NumberToDisplay = 0;
}
function Initialize()
sFileToParse = PROPERTIES.FileToParse
iNumberToDisplay = PROPERTIES.NumberToDisplay
itemPattern = ".-<div class=\"promoItem .-\">.-<a.-href=\"(.-)\".-<img.-src=\"(.-)\".-alt=\"(.-)\".-<span class=\"broadcastChannel\">.-</span>.-</div>"
pattern = ".-<div class=\"listRows \">"
for i=1, 40 do
pattern = pattern..itemPattern
end
tNames = {}
tChannel = {}
tLinks = {}
tImage = {}
end -- function Initialize
function Update()
hReadingFile = io.input(sFileToParse)
sAllText = io.read("*all")
tLinks[1], tImage[1], tNames[1],
tLinks[2], tImage[2], tNames[2],
tLinks[3], tImage[3], tNames[3],
tLinks[4], tImage[4], tNames[4],
tLinks[5], tImage[5], tNames[5],
tLinks[6], tImage[6], tNames[6],
tLinks[7], tImage[7], tNames[7],
tLinks[8], tImage[8], tNames[8],
tLinks[9], tImage[9], tNames[9],
tLinks[10], tImage[10], tNames[10],
tLinks[11], tImage[11], tNames[11],
tLinks[12], tImage[12], tNames[12],
tLinks[13], tImage[13], tNames[13],
tLinks[14], tImage[14], tNames[14],
tLinks[15], tImage[15], tNames[15],
tLinks[16], tImage[16], tNames[16],
tLinks[17], tImage[17], tNames[17],
tLinks[18], tImage[18], tNames[18],
tLinks[19], tImage[19], tNames[19],
tLinks[20], tImage[20], tNames[20],
tLinks[21], tImage[21], tNames[21],
tLinks[22], tImage[22], tNames[22],
tLinks[23], tImage[23], tNames[23],
tLinks[24], tImage[24], tNames[24],
tLinks[25], tImage[25], tNames[25],
tLinks[26], tImage[26], tNames[26],
tLinks[27], tImage[27], tNames[27],
tLinks[28], tImage[28], tNames[28],
tLinks[29], tImage[29], tNames[29],
tLinks[30], tImage[30], tNames[30],
tLinks[31], tImage[31], tNames[31],
tLinks[32], tImage[32], tNames[32],
tLinks[33], tImage[33], tNames[33],
tLinks[34], tImage[34], tNames[34],
tLinks[35], tImage[35], tNames[35],
tLinks[36], tImage[36], tNames[36],
tLinks[37], tImage[37], tNames[37],
tLinks[38], tImage[38], tNames[38],
tLinks[39], tImage[39], tNames[39],
tLinks[40], tImage[40], tNames[40] = string.match(sAllText, pattern)
i = 1
count = 0
while count < 10 and i <= 40 do
if tImage[i].sub(1,1) ~= "h" then
tImage[i] = "http://skyplayer.sky.com"..tImage[i]
end
SKIN:Bang("!RainmeterSetVariable Title"..tostring(count+1).." \""..tNames[i].." - \"")--..tChannel[i].."\"")
SKIN:Bang("!RainmeterSetVariable Link"..tostring(count+1).." \"http://skyplayer.sky.com"..tLinks[i].."\"")
SKIN:Bang("!RainmeterSetVariable Image"..tostring(count+1).." \""..tImage[i].."\"")
count = count+1
i = i+1
end
io.flush(hReadingFile)
end -- function Update
function GetStringValue()
return "Success"
end -- function GetStringValue
Code: Select all
[Rainmeter]
Author=Jeffrey Morley
Update=1000
BackgroundMode=2
SolidColor=100, 100, 100,200
MiddleMouseUpAction=!RainmeterRefresh
@Include=#CURRENTPATH#Settings.inc
[SkyCheck]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=http://skyplayer.sky.com/vod/content/Showcase/Browse_Showcase/Just_Added/content/default/promoPage.do
RegExp="(.*)"
Debug=2
Debug2File=#CURRENTPATH#LuaRainRSS.txt
UpdateRate=300
FinishAction=!RainmeterEnableMeasure SkyCheckLua #CURRENTCONFIG#
[SkyCheckLua]
Measure=Script
ScriptFile="#CURRENTPATH#LuaRainRSS.lua"
TableName=LuaRainRSS
FileToParse="#CURRENTPATH#LuaRainRSS.txt"
NumberToDisplay=10
UpdateDivider=60
Disabled=1
[MeterTitle1]
Meter=String
MeterStyle=TextStyle | Color2Style
Text=#Title1#
Y=42
LeftMouseUpAction=#Link1#
[MeasureImageGrab1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1800
Url=#Image1#
Download=1
DynamicVariables=1
[MeterImage1]
Meter=Image
MeasureName=[MeasureImageGrab1]
DynamicVariables=1
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Parsing troubles
You can't use DyanmicVariables with any plugin in Rainmeter. So what you are probably going to have to do is have two WebParser measures with the full URL and a RegExp, so you actually hit the site twice. Once to create the flat file of the HTML that the Lua will use, and one that just gets the image(s) and downloads them to the current folder (or a subfolder).
Assuming you are doing more than one at a time, this may mean a lot of Measures to get the individual names so you can use them in image meters with ImageName=[MeasureName].
Let me test a few things to see if I can simplify things. I need to chew on this for a bit. I'm thinking "skin" to get the images downloaded, then "lua" to tell the meters which to display. Probably break up the work the lua does into two "sections", so we are not trying to push everything into one big complicated loop.
Assuming you are doing more than one at a time, this may mean a lot of Measures to get the individual names so you can use them in image meters with ImageName=[MeasureName].
Let me test a few things to see if I can simplify things. I need to chew on this for a bit. I'm thinking "skin" to get the images downloaded, then "lua" to tell the meters which to display. Probably break up the work the lua does into two "sections", so we are not trying to push everything into one big complicated loop.