It is currently March 28th, 2024, 1:43 pm

Skin help, WebParser RegExp matching error

Get help with creating, editing & fixing problems with skins
EquusEbon
Posts: 16
Joined: January 1st, 2017, 2:14 pm

Re: Skin help, WebParser RegExp matching error

Post by EquusEbon »

Ok, I finally figured out two of the "errors". The easiest one was the measure MeasureWET. Crazy name to me...it turns out to be used for a wind direction indicator! *GASPS* I'm guessing that Foreca.com had changed slightly how they built webpages, which made the original RegExp match-string bomb out.

Code: Select all

;[MeasureWET]
[MeasureWindDirect]
Measure=Plugin
Plugin=Plugins/WebParser.dll
Url=#wURL1#
;RegExp="(?siU).*img/symb-wind/w(.*).gif" alt=".*".*"
RegExp="(?siU)<img src.*/s/symb-wind/w(.*).gif" alt=".*"
UpdateRate=#UpdateRateSeconds#
StringIndex=1
I know, a measure name is totally arbitrary, but I had to change it to something I would not confuse with precipitation. :o The commented out RegExp is the one that was throwing the expression matching error. The one directly under it works...I learned in the process that Foreca uses numbered images to indicate the direction of the wind vector, and the earlier authors matched that with their own images.

So, this is what my Mass Effect Weather+Radar skin now looks like with he weather 'tab' active:
Mass Efect Weather.PNG
The red-circled item is a funky ellipsis, I would love to move it up and to the left a bit, because it looks off-center. But I've yet to identify a measure that displays it. The yellow-circled arrow is the newly revealed wind vector arrow after I figured out a way to fix the parsing error for MeasureWET.

This leads me to a question. If MeasureWET is there to select the appropriate current wind direction, why was there a need for a second one? At least I think that is what MeasureWET2 is supposed to be.

Code: Select all

;[MeasureWET2]
[MeasureWindDirect2]
Measure=Plugin
Plugin=Plugins/WebParser.dll
Url=#wURL1#
RegExp="(?siU).*img/symb-wind/w(.*).gif" alt="(.*)".*"
UpdateRate=#UpdateRateSeconds#
StringIndex=2
This looks exactly like MeasureWET, but I don't know why it is there. Nor can I figure out where it is displayed.

Oh, the other "error" I sussed out turns out not to be one. It dawned on me that MeasureWeatherIconD and WeatherIconN would only be "defined" on alternating 12 hour periods. Foreca.com would build the webpage using either a "day" set of icons or a "night" set...if they used one with a 'd' appended on the end of the image name, it is from the "day" set, and if the image had an 'n', it was from the "night" set. When WebParser finds one, it will not find the other. So I was chasing a bit of a red herring for awhile. :oops:

Now, if only I can figure out what MeasureF and MeasureOBN were supposed to be originally. As it is, these items not being defined doesn't seem to hurt the skin...maybe I should just comment them out for now?
EquusEbon
Posts: 16
Joined: January 1st, 2017, 2:14 pm

Re: Skin help, WebParser RegExp matching error

Post by EquusEbon »

Well, crud, I think I'm the guy Neo being introduced to "the Matrix" for the first time..."just how far down DOES this rabbit hole go?" Now I have the desire to change the Mass Effect skin to allow myself to "switch" the units displayed from US "English Imperial" to metric and back again. So, first of all, how DOES the WebParser plugin do it's thing? When I go to my city at Foreca.com, it defaults to metric units being displayed. Yet, when I built a Test skin using the script code:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[MeasureSite]
Measure=Plugin
Plugin=WebParser
URL=http://www.foreca.com/United_States/*state*/*city*
RegExp=
Debug=2

[MeterDummy]
Meter=String

[MeasurePicture]
MeasurePlugin
Plugin=WebParser
URL=[MeasureSite]
StringIndex=1
, it seems that it is getting the US "English Imperial" values only, if I am correctly interpreting the WebParserDump.txt file. Is it a CSS thing, since I can toggle from metric to US "English Imperial" and back in a web browser easily, or is there a way to get WebParser to pull the metric information down? I did look at the documentation first, but nothing jumped out at me yelling that "THIS is the way to do it."

Second, if I can't get the metric values that way, would I be looking at a complete rewrite of the existing weather skin to allow myself to do such a toggle if I computed the conversion to metric for temperature, wind speed, and barometric pressure? Doing the conversions individually is easy, but I'm nervous about jumping into Rainmeter scripting blind.

I'm much more comfortable with dealing in compiled languages, in which I know I just have to add three new functions, and a new "unit system state" variable that I can ask "do you want this in metric, or US English Imperial units?" In C, this would mean maybe 15 new lines of code, tops, as a general estimate. I've never tried Perl, PHP, or even javascript before, so you might see why I'm feeling so nervous about doing this. :oops:
EquusEbon
Posts: 16
Joined: January 1st, 2017, 2:14 pm

Re: Skin help, WebParser RegExp matching error

Post by EquusEbon »

balala wrote:As jsmorley said, just add his ImageCrop=0,129,1280,591 option to the [Radar] meter. But if you do so, another problem will occur: when you'll click the Radar tab of the skin (to see the downloaded image), the Feels like string from the Weather tab will remain visible. The simplest solution to "vanish" it, would be to add to the same [Radar] meter a SolidColor=0,0,0 option, which will fill the surface of the image meter uncovered by the image itself, with a black background. This will cover the Feels like string.
A minor milestone...I ferretted out what was causing that "Feels Like:" string to display 'under' the chosen image map. There was a hard-to-spot !ShowMeter buried in the middle of the !HideMeters in the ButtonCommand=!execute construct of the ButtonRadarPassive meter. Though the logic of its name was the opposite of what I'd have used to name it...it hides all the Weather "tab" elements, making the Weather "tab" the "passive" one...and the Radar "tab" the "active" one...to keep those elements from cluttering up the image map in the active Radar "tab" of the meter. And after commenting out 4 other apparently 'dead' meters, I'm down to one error...the aforementioned 12-hour window when one icon set is used at Foreca to show the difference in day and night.

This is what I've ended up with:
Mass Effect Weather20170115_0.PNG
Mass Effect Weather20170115_1.PNG
These two screen captures shows the information I managed to squeeze in, while the next one shows the result if the Radar "tab" does not get an image to display:
Mass Effect Weather20170115_2.PNG
I am open to suggestions about how to go about getting this skin to have some type of "measurement unit switch" to let me choose to use metric or US English Imperial. I thought about a relatively simple 'variable' in the skin script to let me do this...requires editing the skin once the additional code was done...but it seems like that method would swell the script code by 80% again, since I'd be dealing with two values for air pressure, each individual instance of temperature, wind speed, dew point, and wind chill/heat index. Does my thinking seem reasonable, as I am new to Rainmeter?

Oh, in the attachment "Mass Effect Weather20170115_0.png" (the first one, I circled the string "Fog" and an ellipsis above and offset to the right of that string). If I'm understanding the manual right, that ellipsis is a direct result of the ClipString meter(?). Is there another way I could clip the string and NOT have that ellipsis throw a visual monkey wrench into the works? The code of interest is this:

Code: Select all

[MeterFO]
Meter=String
MeasureName=MeasureFO
X=r
Y=r
w=160
h=40
FontFace=#FontFace#
FontSize=#FontSize5#
FontColor=#ColorF#
StringStyle=BOLD
StringAlign=CenterTop
AntiAlias=1
ClipString=1
EquusEbon
Posts: 16
Joined: January 1st, 2017, 2:14 pm

Re: Skin help, WebParser RegExp matching error

Post by EquusEbon »

jsmorley wrote:WEB_Current_Weather_Map_1280x720.jpg

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeterRadar]
Meter=Image
ImageName=#@#Images\WEB_Current_Weather_Map_1280x720.jpg
ImageCrop=0,129,1280,591
W=600
PreserveAspectRatio=1
The important thing to wrap your head around with ImageCrop is that the area you define is what you are "keeping", not what you are "cropping off".
Ah, I understand the part about the thing keeping part of the image, but I'm a bit confused about where it is starting from to decide what to keep. The documentation says the default "starting location" is the "top left" of the image being pulled in....

OIC, I think. You are telling Rainmeter to drop down 129 pixels from the top left corner of the original image, then keep the image 1280 pixels to the right of that point, then down 591 pixels? I am slightly confused because the example in the documentation says that there are five starting points, and used the center starting point without saying how to tell ImageCrop to actually start in the center. At least, that is what I think happened. If I did want to start from the center of the image, how would I tell ImageCrop to do so?

Whups, my dyslexia kept me from seeing that there can be FIVE parameters, if using the fifth, that is where you can say where you want to start from. So, if I wasn't depending on the default for ImageCrop, I could do the same this way:ImageCrop=0,129,1280,591,1 D'oh, I feel like a dunce for not catching that sooner. :x

But why do you define "W" to be 600? I thought the image is 1280 pixels wide, not just 600. I realize it is something to do with the container for the meter, but I'm not quite grokking what the link is...yet.
Last edited by EquusEbon on January 23rd, 2017, 2:17 am, edited 1 time in total.
EquusEbon
Posts: 16
Joined: January 1st, 2017, 2:14 pm

Re: Skin help, WebParser RegExp matching error

Post by EquusEbon »

And one more question. I am not quite getting how conditional statements work. I defined a variable 'UnitSystem' that I've set to the number zero. What I want to do is to look at the value of UnitSystem, and see if it equals the number zero...if it does, then set the variable TempUnit to the string "C", else set the variable TempUnit to the string "F". I'm probably misreading the documentation in expecting the following to work as is:

Code: Select all

UnitSystem=1
TempUnit="none"

(#UnitSystem#=0) ? (TempUnit="°C") : (TempUnit="°F")
;Assign the string "°C" to TempUnit if UnitSystem=0, else assign the string "°F" to TempUnit
TempUnit never gets reset to a new string, it stays "none". So how am I looking at conditionals wrong? I'm used to doing this in compiled code using the traditional "IF...THEN...ELSE..." construct, where the variable can be BOOLEAN, and thus can be equivalent to TRUE or FALSE in and of itself.

I did think of trying it this way:

Code: Select all

TempUnit=(#UnitSystem#=0) ? (TempUnit="°C") : (TempUnit="°F")
, but this makes my instincts scream "WRONG SYNTAX...IT'S NOT BALANCED!!" at me. :? Sorry for the caps, it is just how strong the warning-off feels.

Actually, I think a CASE facility would be more useful in this instance...but I need to learn how to walk correctly before moving on to trying to run. I am not even sure if there is a CASE facility I this. :oops: Any direction or tip would be much appreciated.

Ah, I failed to mention that I've upgraded to Rainmeter 4.0 from 3.2 in mid-thread. That probably doesn't matter, but I am working on a single monitor setup on Windows 10 Anniversary Update (personally, I think it is easier to say WinX.1, but I'm not Microsoft! Probably a trademark issue with the 'toon "the Winx Club") :p :rofl:
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Skin help, WebParser RegExp matching error

Post by jsmorley »

Code: Select all

[Variables]
UnitSystem=0
TempUnit="none"

[MeasureTestUnit]
Measure=Calc
Formula=#UnitSystem#
IfCondition=MeasureTestUnit = 0
IfTrueAction=[!SetVariable TempUnit "°C"]
IfFalseAction=[!SetVariable TempUnit "°F"]
;Assign the string "°C" to TempUnit if UnitSystem=0, else assign the string "°F" to TempUnit
Conditional statements in a Calc measure or other formula are strictly "numeric". Both the "test" and the "result" can only be numbers or other formulas that resolve to numbers.
Note: While [Measures], [SectionVariables:] and #Variables# can be used in a formula, all the components of a formula must be numeric, using only numbers, operators, functions and constants.
https://docs.rainmeter.net/manual/formulas/#Conditional

So what we are doing here is using a Calc measure to get and evaluate the value of the variable #UnitSystem". We use an IfCondition option to test, which is used to evaluate numbers and formulas for a "true / false" condition, and then we can fire IfTrueAction / IfFalseAction action options that can execute any bangs we want. In this case, we want to use !SetVariable to set the variable #TempUnit# to one of the two strings.

https://docs.rainmeter.net/manual/measures/general-options/ifconditions/
https://docs.rainmeter.net/manual/bangs/#SetVariable

Note, if we wanted to test a "string" value rather than a numeric value, we would use IfMatch instead of IfCondition.

https://docs.rainmeter.net/manual/measures/general-options/ifmatchactions/

I caution against thinking of Rainmeter as if were a "procedural programming language". It's not in any way... Measures "measure" stuff, and Meters "display" stuff. At the root, it's simply that. Anything that is to to the left of the "=" sign in both measures and meters are "options". They are never "statements", and something like TempUnit = "°C" is never valid anywhere in Rainmeter.
Post Reply