It is currently May 8th, 2024, 10:09 am

RegExp error - [MeasureLocationWeather] Matching error! (-1)

Get help with creating, editing & fixing problems with skins
User avatar
qwertyoctopus
Posts: 17
Joined: November 26th, 2010, 4:49 am

RegExp error - [MeasureLocationWeather] Matching error! (-1)

Post by qwertyoctopus »

Hi,

I'm using WebParser to automatically update my location and attached is a screenshot of RainRegExp.

Anyway, here's my code:

Code: Select all

[MeasureLocationWeather]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url="http://www.maxmind.com/app/locate_my_ip"
RegExp="(?siU)Global Cities.*"center"> (.*)</td>"
StringIndex=1

[MeterLocationWeather]
Meter=String
MeasureName=MeasureLocationWeather
FontFace=Raleway
FontSize=72
StringAlign=Center
W=750
X=(1366/2)
Y=200
Debug=1
FontColor=45,100,255
AntiAlias=1
And here's the debug file:

Code: Select all

DEBUG: (00:30:25.773) WebParser: Fetching URL: http://www.maxmind.com/app/locate_my_ip
DEBUG: (00:30:25.992) WebParser: Finished URL: http://www.maxmind.com/app/locate_my_ip
DEBUG: (00:30:25.992) WebParser: [MeasureLocationWeather] Matching error! (-1)
My Rainmeter skills are kind of rusty and I'd be willing to bet that it's a really noobish error on my part, but I'm just not seeing it.

Thanks in advance for any help.
-Michael
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegExp error - [MeasureLocationWeather] Matching error!

Post by jsmorley »

There is a line break in the HTML that is returned that you are not accounting for in your regular expression.

If you use:

RegExp="(?siU)Global Cities.*"center">\n(.*)</td>"

Your skin will work fine.

NOTE! In RainRegExp, when you connect to a site the HTML is displayed with line breaks using the "Windows / DOS" convention for "carriage return / linefeed" which is \r\n. WebParser on the other hand saves and parses what it receives using the "unix" convention of just "linefeed" or \n

The point of this is that to test in RainRegExp you will need to use \r\n to specifically indicate a line break, but will need to remove the \r part before you use it in Rainmeter.

Another, and probably better way to solve this is to use a construct like:

(?siU)Global Cities.*"center">[\s]{1,2}(.*)</td>

The bold part in this says "search for any non-printable character, which is space, tab, carriage return, linefeed, etc, with there being at least one, and at most two"

That will match on a line break in either a Windows or Unix format file.
7-19-2011 12-13-48 AM.jpg
Another approach that is "generic" is:

RegExp="(?siU)Global Cities.*"center">[\r\n | \n](.*)</td>"

This means \r\n OR \n
You do not have the required permissions to view the files attached to this post.
User avatar
qwertyoctopus
Posts: 17
Joined: November 26th, 2010, 4:49 am

Re: RegExp error - [MeasureLocationWeather] Matching error!

Post by qwertyoctopus »

Thanks! That worked perfectly. I have one quick question though. Now I want to use the return of that measure as a variable in another web parsing measure. I actually have to plug it into the URL. Is that possible, or do I have to find a different way?

Thanks again,
Michael
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegExp error - [MeasureLocationWeather] Matching error!

Post by jsmorley »

WebParser measures can't have dynamic variables, so it would be impossible to use any straightforward way to use the result of one WebParser measure as part of the URL of a second one.

I'm sure there is some kind of work around, but I'll have to think about it. Nothing is coming to mind, but then I am just about to go get my first cup of coffee from the brewer, so I'm still having trouble getting my brain to stop stalling at every traffic light.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: RegExp error - [MeasureLocationWeather] Matching error!

Post by Kaelri »

How much variation is there in the results of the first measure? (In other words, how many cities do you want to be able to use this with? Or do you want it to work generically?)
User avatar
qwertyoctopus
Posts: 17
Joined: November 26th, 2010, 4:49 am

Re: RegExp error - [MeasureLocationWeather] Matching error!

Post by qwertyoctopus »

Yeah, I was planning on having this be a generic skin.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: RegExp error - [MeasureLocationWeather] Matching error!

Post by Kaelri »

Hm. Ok, I have an idea. The user's location isn't something that's going to change with any great frequency, which means you don't need to check it every time the skin is loaded. So I would add a new measure, which writes the location result to a variable and disables the original WebParser measure:

Code: Select all

[MeasureLocationReceived]
Measure=CALC
Formula=1
DynamicVariables=1
IfEqualValue=1
IfEqualAction=!Execute [!WriteKeyValue Variables Location [MeasureLocationWeather]][!WriteKeyValue MeasureLocationWeather Disabled 1][!Refresh]
Disabled=1
Because this function needs a result from [MeasureLocationWeather] before it can run, it should be disabled until it's turned on by a FinishAction from your original measure:

Code: Select all

[MeasureLocationWeather]
...
FinishAction=!EnableMeasure MeasureLocationReceived
Now you can write your new measure, which is able to use the variable #Location# in its URL. (You should provide a default value for this variable, so that the skin doesn't throw errors the first time it loads.)

You'll also want to add a button or something to reverse the actions of [MeasureLocationReceived] in order to reset the location.

Code: Select all

[ResetButton]
...
LeftMouseUpAction=!Execute [!WriteKeyValue MeasureLocationWeather Disabled 0][!Refresh]
Caveat: I haven't tested any of this. But it should work in theory.
User avatar
qwertyoctopus
Posts: 17
Joined: November 26th, 2010, 4:49 am

Re: RegExp error - [MeasureLocationWeather] Matching error!

Post by qwertyoctopus »

It was giving me various !bang errors, but I sorted them out. But now it isn't showing anything.

Code: Select all

[MeasureLocationWeather]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url="http://www.maxmind.com/app/locate_my_ip"
RegExp="(?siU)Global Cities.*"center">[\s]{1,2}(.*)</td>"
StringIndex=1
Disabled=0

[MeasureLocationReceived]
Measure=CALC
Formula=1
DynamicVariables=1
IfEqualValue=1
IfEqualAction=!Execute [!WriteKeyValue Variables Location [MeasureLocationWeather]][!WriteKeyValue MeasureLocationWeather Disabled 1][!RainmeterRefresh]
Disabled=1

[MeasureLocationWeather2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url="http://free.worldweatheronline.com/feed/weather.ashx?q=#Location#&format=xml&num_of_days=2&key=561b793aa8222605111607"
RegExp="(?siU)<temp_F>(.*)</temp_F>"
StringIndex=1
FinishAction=!RainmeterEnableMeasure MeasureLocationReceived

[MeterLocationWeather]
Meter=String
MeasureName=MeasureLocationWeather
MeasureName2=MeasureLocationWeather2
FontFace=Raleway
FontSize=72
W=500
Y=100
Debug=1
FontColor=45,100,255
Text=%2 F
AntiAlias=1
LeftMouseUpAction=!Execute [!RainmeterWriteKeyValue MeasureLocationWeather Disabled 0][!RainmeterRefresh]
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: RegExp error - [MeasureLocationWeather] Matching error!

Post by Kaelri »

The FinishAction needs to be on the first WebParser measure, not the second.

You also don't need "MeasureName=MeasureLocationWeather" on your meter (and in fact, if you do, it won't work, because the measure is disabled after the first run). You can just use the #Location# variable instead.

I tested it with those changes, and it works. :)
User avatar
qwertyoctopus
Posts: 17
Joined: November 26th, 2010, 4:49 am

Re: RegExp error - [MeasureLocationWeather] Matching error!

Post by qwertyoctopus »

It wasn't working for me with the changes, so I tried rewriting it and it still didn't work. So I reverted back to the version that worked for you(still didn't work) and here's the code:

Code: Select all

[MeasureLocationWeather]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url="http://www.maxmind.com/app/locate_my_ip"
RegExp="(?siU)Global Cities.*"center">[\s]{1,2}(.*)</td>"
StringIndex=1
Disabled=0
FinishAction=!RainmeterEnableMeasure MeasureLocationReceived

[MeasureLocationReceived]
Measure=CALC
Formula=1
DynamicVariables=1
IfEqualValue=1
IfEqualAction=!Execute [!WriteKeyValue Variables Location [MeasureLocationWeather]][!WriteKeyValue MeasureLocationWeather Disabled 1][!RainmeterRefresh]
Disabled=1

[MeasureLocationWeather2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url="http://free.worldweatheronline.com/feed/weather.ashx?q=#Location#&format=xml&num_of_days=2&key=561b793aa8222605111607"
RegExp="(?siU)<temp_F>(.*)</temp_F>"
StringIndex=1

[MeterLocationWeather]
Meter=String
MeasureName=MeasureLocationWeather2
FontFace=Raleway
FontSize=72
W=500
Y=100
Debug=1
FontColor=45,100,255
Text=%1 F
AntiAlias=1
LeftMouseUpAction=!Execute [!RainmeterWriteKeyValue MeasureLocationWeather Disabled 0][!RainmeterRefresh]
And here's an excerpt from my log file
DEBUG: (08:38:57.722) !RainmeterWriteKeyValue: Writing file: C:\Users\Michael\Documents\Rainmeter\Skins\Dark Wood\GeoIP\GeoIP.ini
NOTICE: (08:38:57.722) Refreshing skin "Dark Wood\GeoIP\GeoIP.ini"
DEBUG: (08:38:57.722) Reading file: C:\Users\Michael\AppData\Roaming\Rainmeter\Rainmeter.ini
DEBUG: (08:38:57.753) Reading file: C:\Users\Michael\Documents\Rainmeter\Skins\Dark Wood\GeoIP\GeoIP.ini
DEBUG: (08:38:57.769) WebParser: Fetching URL: http://www.maxmind.com/app/locate_my_ip
DEBUG: (08:38:57.769) WebParser: Fetching URL: http://free.worldweatheronline.com/feed/weather.ashx?q=#Location#&format=xml&num_of_days=2&key=561b793aa8222605111607
DEBUG: (08:38:58.081) !RainmeterWriteKeyValue: Writing file: C:\Users\Michael\Documents\Rainmeter\Skins\Dark Wood\GeoIP\GeoIP.ini
NOTICE: (08:38:58.081) Refreshing skin "Dark Wood\GeoIP\GeoIP.ini"
DEBUG: (08:38:58.081) Reading file: C:\Users\Michael\AppData\Roaming\Rainmeter\Rainmeter.ini
DEBUG: (08:38:58.112) Reading file: C:\Users\Michael\Documents\Rainmeter\Skins\Dark Wood\GeoIP\GeoIP.ini
DEBUG: (08:38:58.127) WebParser: Fetching URL: http://www.maxmind.com/app/locate_my_ip
DEBUG: (08:38:58.127) WebParser: Fetching URL: http://free.worldweatheronline.com/feed/weather.ashx?q=#Location#&format=xml&num_of_days=2&key=561b793aa8222605111607
DEBUG: (08:39:58.125) WebParser (1639) The operation timed out (ErrorCode=12002)

(By the way, thank you so much for helping me, I'm really thankful that you took the time to help me with my Rainmeter troubles) :)