It is currently May 8th, 2024, 2:55 am

Help with RegExp

Get help with creating, editing & fixing problems with skins
Ryzaar
Posts: 4
Joined: March 22nd, 2012, 4:54 am

Help with RegExp

Post by Ryzaar »

Just wondering why this won't work?

The first string parses fine, but I get N/A for my Min and Max weather :s I've never coded this before, I'm simply editing another script, so I honestly have no idea! :p

Code: Select all

[MeasureWeather]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=2400
Url=http://users.on.net/~johnson/weather/wea_all_rss.php?cities=ADELAIDE
RegExp="(?siU)<title>ADELAIDE - (.*). Max:"

[MeasureWeather2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=2400
Url=http://users.on.net/~johnson/weather/wea_sa_rss.php
RegExp="(?siU)<title>Glenelg</title>.*day: (.*) Min Max (.*)</br>"

[MeasureCText]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWeather]
StringIndex=1
Substitute=" developing":""

[MeasureMin2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWeather2]
StringIndex=2
Substitute="":"N/A"

[MeasureMax2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWeather2]
StringIndex=3
Substitute="":"N/A"

[TodayTempString]
Meter=STRING
MeterStyle=TextRightStyle
MeasureName=MeasureCText
X=0
Y=40r
FontColor=#Color1#
FontSize=30
FontFace=#LocalFontFace#
StringAlign=left
AntiAlias=1

[TodayMin]
Meter=STRING
MeterStyle=TextRightStyle
MeasureName=MeasureMin2
W=200
X=50
Y=-3
FontColor=60, 160, 255, 180
FontSize=29
FontFace=#LocalFontFace#
StringAlign=Right
AntiAlias=1

[TodayMax]
Meter=STRING
MeterStyle=TextRightStyle
MeasureName=MeasureMax2
W=200
X=350
Y=-3fa
FontColor=60, 160, 255, 180
FontSize=29
FontFace=#LocalFontFace#
StringAlign=Right
AntiAlias=1
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with RegExp

Post by jsmorley »

Not quite sure what this skin is trying to do as you are getting the conditions for one city then the "min / max" for another, but the long and the short of it is that you have to wrap your head around how WebParser works with regular expressions (RegExp=) if you want to edit an existing skin and change what it is getting / doing.

The RegExp= statement searches for starting and ending patterns you define, and when it finds the pattern, you tell it to return everything between the start and end with (.*).

So in that first measure [MeasureWeather], you could use RegExp="(?siU)<title>ADELAIDE - (.*). Min: (.*) Max: (.*)</title>". Since the actual text in the feed is <title>ADELAIDE - Shower or two. Min: 14 Max: 19</title> what we will get is three "StringIndexes", with "Shower or two" in the first, "14" in the second, and "19" in the third.

Then you need to build a measure for each of those StringIndexes, to pick off the value in each and assign it to a measure we can then use in your meters.

So you would have the "parent" measure getting all the info at once, and three "child" measures that each contain one of the values:

Code: Select all

[MeasureWeather]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=2400
Url=http://users.on.net/~johnson/weather/wea_all_rss.php?cities=ADELAIDE
RegExp="(?siU)<title>ADELAIDE - (.*). Min: (.*) Max: (.*)</title>"

[MeasureCText]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWeather]
StringIndex=1

[MeasureMin1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWeather]
StringIndex=2

[MeasureMax1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWeather]
StringIndex=3
Now you can use those child measures in meters to display information:
[TodayTempString]
Meter=STRING
MeterStyle=TextRightStyle
MeasureName=MeasureCText
X=0
Y=40r
FontColor=#Color1#
FontSize=30
FontFace=#LocalFontFace#
StringAlign=left
AntiAlias=1

[TodayMin]
Meter=STRING
MeterStyle=TextRightStyle
MeasureName=MeasureMin1
W=200
X=50
Y=-3
FontColor=60, 160, 255, 180
FontSize=29
FontFace=#LocalFontFace#
StringAlign=Right
AntiAlias=1

[TodayMax]
Meter=STRING
MeterStyle=TextRightStyle
MeasureName=MeasureMax1
W=200
X=350
Y=-3fa
FontColor=60, 160, 255, 180
FontSize=29
FontFace=#LocalFontFace#
StringAlign=Right
AntiAlias=1
As I said, I'm a little confused why you are going to two different URL's and getting a mix of two cities, but that may be exactly what you want. You can just build a second "parent" measure for the second site / url, and then as many new "child" measures as you need to pick off the values from that measure. Then use them in additional meters as you need.

You are going to be stabbing in the dark a bit if you don't get a handle on WebParser and RegExp though. I recommend:

http://rainmeter.net/cms/Rainmeter101
http://rainmeter.net/cms/Plugins-WebParser_beta
http://rainmeter.net/cms/Tips-WebParserPrimer
Ryzaar
Posts: 4
Joined: March 22nd, 2012, 4:54 am

Re: Help with RegExp

Post by Ryzaar »

Ah, the reason why I used two URLs, is because the first gives a text description of the weather and the max for South Australia. It doesn't offer a min temperature except for the days following (mine only says "<title>ADELAIDE - Shower or two. Max: 19</title>").

The second URL grabs the min and max temperatures for specific cities in South Australia (hence why I've included Glenelg in RegExp). The end result that I was after was the text description of the weather for South Australia (e.g. 'shower or two'), and the min and max temperatures for Glenelg (a city of South Australia).

I turned on logging and found this in the file:

Code: Select all

ERROR: (25:48:12.200) WebParser.dll: [MeasureWeather2] Matching error! (-1)
Does that mean it could not find the string I was asking it to search for?
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with RegExp

Post by jsmorley »

Ryzaar wrote:Does that mean it could not find the string I was asking it to search for?
Correct. You need to take a look at the "source" of the web page (you can use "view page source" in firefox) and compare it to the RegExp (regular expression) you have.
Ryzaar
Posts: 4
Joined: March 22nd, 2012, 4:54 am

Re: Help with RegExp

Post by Ryzaar »

Part of the way down the page there is this:

Code: Select all

<item>
<title>Glenelg</title>
<link>http://www.bom.gov.au/weather/national/</link>
<description>
Friday: 16 Min Max 19<br />Saturday: 25 Min 14 Max 20<br />Sunday: 15 Min 13 Max 20<br />Monday: 27 Min 12 Max 22<br />Tuesday: Min 14 Max 24
</description>
</item>
I have tried this:

Code: Select all

RegExp="(?siU)<title>Glenelg</title>.*day: (.*) Min Max (.*)<br />"
To extract 16 and 19 out of "Friday: 16 Min Max 19"
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with RegExp

Post by jsmorley »

Ryzaar wrote:Part of the way down the page there is this:

Code: Select all

<item>
<title>Glenelg</title>
<link>http://www.bom.gov.au/weather/national/</link>
<description>
Friday: 16 Min Max 19<br />Saturday: 25 Min 14 Max 20<br />Sunday: 15 Min 13 Max 20<br />Monday: 27 Min 12 Max 22<br />Tuesday: Min 14 Max 24
</description>
</item>
I have tried this:

Code: Select all

RegExp="(?siU)<title>Glenelg</title>.*day: (.*) Min Max (.*)&"
To extract 16 and 19 out of "Friday: 16 Min Max 19"

Code: Select all

RegExp="(?siU)<title>Glenelg</title>.*day: (.*) Min.*Max (.*)<"
There seems to be more than one space between "Min" and "Max", so I just changed it to ignore any number of chars between them. Also, if you look at the actual HTML code, you will see that it is really:

Code: Select all

      <item>
        <title>Glenelg</title>
        <link>http://www.bom.gov.au/weather/national/</link>
        <description>Friday: 16 Min   Max 19<br />Saturday: 25 Min 14  Max 20<br />Sunday: 15 Min 13  Max 20<br />Monday: 27 Min 12  Max 22<br />Tuesday:  Min 14  Max 24</description>
      </item>
After "Max 19" it has the code for "less than" rather than the actual character, and the RegExp needs to be written against the raw HTML code, not what it looks like in the browser. Those extra spaces between "Min" and "Max" are ignored by a browser, but not by WebParser. Same with the < after "Max 19". It will display as "<" in a browser, but in fact is "<" in code.

* Note: It is remotely possible that the raw HTML sent to you is slightly different than what I get. This would be possible if the application on the server-side is reacting to different browsers, (firefox vs chrome vs internet explorer for instance) and outputting slightly different HTML to allow for differences in how browsers render things. This is VERY unlikely in an RSS feed like this, but worth keeping in mind if what I propose you use doesn't seem to work.

You need to use "view page source" in your browser so you can see the actual raw HTML that is being sent. Your browser will lie to you, as it wants to "render" it properly.

Another option, and one I recommend, is to get and use RainRegExp: http://rainmeter.net/forum/viewtopic.php?p=5635#p5635 to help with creating those RegExp statements.
3-22-2012 11-15-50 PM.jpg
You do not have the required permissions to view the files attached to this post.
Ryzaar
Posts: 4
Joined: March 22nd, 2012, 4:54 am

Re: Help with RegExp

Post by Ryzaar »

Thank you, that worked great. I did assume that the XML format was the right format, so thanks for clearing the whole raw HTML thing up!

I'll check that tool out, but once again, thanks for the help! :)
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with RegExp

Post by jsmorley »

I can't recommend RainRegExp highly enough if you are going to be doing much RegExp stuff. It can really make things a lot quicker and easier.

In any case, glad to help.