It is currently February 5th, 2023, 1:18 pm

Using string value of a measure in WebParser RegExp

Get help with creating, editing & fixing problems with skins
User avatar
MazinLabib10
Posts: 4
Joined: January 21st, 2023, 3:47 pm

Using string value of a measure in WebParser RegExp

Post by MazinLabib10 »

Hey everyone!

I'm currently in the process of making my first ever skin from scratch. The skin shows the previous and next game for any football/soccer team of your choosing. The data for this comes from a website called BeSoccer and, for the sake of testing, I'm using my favorite team, Manchester United.

As you can see, each fixture on the team page shows the name of the competition that match is contested in but not the logo. So, I'm looking for a way to use WebParser to use the name of the competition to retrieve its logo. At the moment I have got it working by having the logos downloaded locally for the competitions where Man. United are involved. However, as I am looking to have this skin work for almost any team in world football, it would be ridiculous to include around 1200 logos (for all the competitions available on the site) in the .rmskin package.

So my plan is to create a .txt file that contains all the competition names along with a link to their logos. Then, the competition name can be collected from the site using WebParser and then another WebParser will search the .txt for that competition and return the link to its logo which can then be downloaded in another measure.

Here is the code I'm testing on:

Code: Select all

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

[MeasureSite]
Measure=WebParser
URL=https://www.besoccer.com/team/matches/manchester-united-fc
RegExp=(?siU)<div class="panel-title">Upcoming Matches</div>.*<div class="middle-info ta-c">(.*)</div>

[MeasureCompetition]
Measure=WebParser
URL=[MeasureSite]
StringIndex=1

[MeasureText]
Measure=WebParser
URL=file://#CURRENTPATH#Test.txt
RegExp=(?siU)[MeasureCompetition]: (.*)\r
DynamicVariables=1

[MeasureLogoLink]
Measure=WebParser
URL=[MeasureText]
StringIndex=1
Download=1

[MeterLogo]
Meter=Image
MeasureName=MeasureLogoLink
H=120
DynamicVariables=1
In this case, [MeasureCompetition] returns "Premier League". Now, here is the contents of the Test.txt file, for now:

Code: Select all

La Liga: https://cdn.resfu.com/img_data/competiciones/logo/1.png
Premier League: https://cdn.resfu.com/img_data/competiciones/logo/10.png
The problem arises in the RegExp of the [MeasureText] section. I'm not able to find a way to use the string value of [Measure Competition] in the RegExp. This reply by jsmorely states that what I've done above should work, but for some reason it doesn't. It just ignores the name of the measure and starts searching from the : onwards. I've searched a lot but can't find a solution. Anyone have any idea?

Edit: Forgot to mention, I tried to do it using variables, and it worked when I had assigned a static string value to the variable. But when I tried assigning the value of the measure to the variable, it stopped working.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2250
Joined: March 23rd, 2015, 5:26 pm

Re: Using string value of a measure in WebParser RegExp

Post by SilverAzide »

MazinLabib10 wrote: January 21st, 2023, 4:44 pm
You probably have a timing problem. WebParser runs on a separate thread from the main Rainmeter app, so it processes data as it comes back from the website. The problem most likely is that [MeasureText] is executing before [MeasureCompetition] (and it's parent, [MeasureSite]) have finished retrieving any data. As a result, the RexExp expression is "(?siU): (.*)\r" which probably isn't working, so [MeasureLogoLink] returns nothing (or the first row in the file, not sure which).

The solution is to delay the processing until the values are fetched. In other words, set Disabled=1 on the children and other measures that depend on them. Then, on the parent WebParser, use a FinishAction=[!EnableMeasure ...][etc] to enable the child measures once the parent has obtained a value. Or use a Group option on all the children so you enable them in one go using an !EnableMeasureGroup bang.
Gadgets Wiki GitHub More Gadgets...
User avatar
MazinLabib10
Posts: 4
Joined: January 21st, 2023, 3:47 pm

Re: Using string value of a measure in WebParser RegExp

Post by MazinLabib10 »

Yes, that did it! All I had to do was add Disabled=1 to [MeasureText] and then add FinishAction=[!EnableMeasure MeasureText] to [MeasureSite] and now it works as intended. Was turning into a real headache but you've solved it for me. Thank you so much! :thumbup:
SilverAzide wrote: January 21st, 2023, 5:30 pm As a result, the RexExp expression is "(?siU): (.*)\r" which probably isn't working, so [MeasureLogoLink] returns nothing (or the first row in the file, not sure which).
Just fyi, it was returning the link from the first row, as you thought.