It is currently August 19th, 2022, 8:34 pm

[Solved] Webparser shows value 0 with lua scripting

Get help with creating, editing & fixing problems with skins
User avatar
Missing
Posts: 4
Joined: July 28th, 2022, 8:28 pm

[Solved] Webparser shows value 0 with lua scripting

Post by Missing »

Hello,
I have been working on a skin that takes the recently played games on your steam profile and can launch them from their icon on the skin.
The problem with the skin is that it won't show any games if you have less than 5 games in recent (I decided that the max nb of games shown would be 5).
On my measure that gets the ID and the logo of each games, I copied appid":(.*),.*logo":"(.*)",.* 5 times as the RegExp, for the number of games I want to get. If I had 4 games, then I would simply need to copy it 4 times for the skin to work. However, I'd like it to be user friendly.

To counter this problem, I wrote a small LuaScript that counts the number of games in recent with the number of appearance of "Appid". With the result of that count, I create a sequence of appid":(.*),.*logo":"(.*)",.* with the length needed. This result would then be sent to my skin as a variable and this variable it used for my RegExp. On paper it works...

I have a string meter to make sure the result of my Lua is good, and it does show me the right thing. But when I put the result of Lua in my webparser, it gives me a value of zero.
Image
When I would expect something like that.
Image

I tried a lot of things and looked at many post to see if their could be a way to fix that. I don't understand why the variable shows up right on my string meter but gives me a value of 0 on my webparser measure.

To help, my variable that uses the Lua result is NbGames and that variable is used for [MeasureAll].

I really hope a solution exists and I just didn't find it. Thank you.

Here are my script:
UserVariables.inc

Code: Select all

[Variables]
Game=appid":(.*),.*logo":"(.*)",.*


; appid":(.*),.*logo":"(.*)",.*

; Thumbnails dimensions
Width=146
Height=55

; Put your steam ID name after SteamID=
SteamID=imsash

;Panel Color
ColorSkin=50,50,50
;Panel Color on hover
ColorSkin2=255,80,247
;Panel Opacity
Opacity=175

;Number of games
NbGames=5

CountGames.lua

Code: Select all

function Initialize()

	feedMeasure = SKIN:GetMeasure('MeasureNbGames')

end


function Update()
	feedData = feedMeasure:GetStringValue()
	dummyVar, numberOfItems = string.gsub(feedData, 'appid', "")
	Game = SKIN:GetVariable('game', 'n/a')
	g = string.rep(Game,numberOfItems)
	return tostring(g)
end


SteamRecent.ini

Code: Select all

[Rainmeter]
Update=500
OnUnfocusAction=[!SetVariable ToggleVar 1][!UpdateMeter MeterPanel][!Redraw][!HideMeter MeterGame1Image][!HideMeter MeterGame2Image][!HideMeter MeterGame3Image][!HideMeter MeterGame4Image][!HideMeter MeterGame5Image][!HideMeter MeterSteamImage][!UpdateMeter *][!Redraw]

RightMouseUpAction=[!SkinCustomMenu]
ContextTitle=Settings
ContextAction=["#@#Config\config.exe" #PanelType# "#CURRENTCONFIG#" "#CURRENTFILE#" "#SETTINGSPATH#" "#SKINSPATH#" "#PROGRAMPATH#"]
ContextTitle2=Refresh
ContextAction2=[!Refresh #CurrentConfig#]
ContextTitle3=Unload
ContextAction3=[!DeactivateConfig]
ContextTitle4=----
ContextAction4=[]
ContextTitle5=MoreActions
ContextAction5=[!SkinMenu]


[Variables]
@include=#@#UserVariables.inc
ToggleVar=1
NbGames=(?siU)[&MeasureLuaScript:Update()]
; GamesID="appid":(.*),.*logo":"(.*)",.*appid":(.*),.*logo":"(.*)",.*"


; Timers 

[Timer]
Measure=Calc
Formula=( Timer + 1 )
Disabled=1
IfCondition=(Timer=1)
IfTrueAction=[!HideMeter MeterGame1Image][!HideMeter MeterGame2Image][!HideMeter MeterGame3Image][!HideMeter MeterGame4Image][!HideMeter MeterGame5Image][!HideMeter MeterSteamImage][!SetVariable ToggleVar "1"][!DisableMeasure Timer][!UpdateMeter *][!Redraw]

[MeasureNbGames]
Measure=WebParser
URL=https://steamcommunity.com/id/#SteamID#/games/?tab=recent
RegExp=(?siU)var rgGames(.*)var
UpdateRate=300

[MeasureLuaScript]
Measure=Script
ScriptFile=#@#CountGames.lua
Disabled=1
UpdateDivide=-1


[MeasureAll]
Measure=WebParser
URL=https://steamcommunity.com/id/#SteamID#/games/?tab=recent
RegExp=#NbGames#
UpdateRate=300
FinishAction=[!CommandMeasure MeasureGame1ImageDL "Update"][!CommandMeasure MeasureGame2ImageDL "Update"][!CommandMeasure MeasureGame3ImageDL "Update"][!CommandMeasure MeasureGame4ImageDL "Update"][!CommandMeasure MeasureGame5ImageDL "Update"][!HideMeter MeterGame1Image][!HideMeter MeterGame2Image][!HideMeter MeterGame3Image][!HideMeter MeterGame4Image][!HideMeter MeterGame5Image][!SetVariable ToggleVar "1"][!HideMeter MeterSteamImage]


[MeasureSteam]
Measure=WebParser
URL=https://steamcommunity.com/id/#SteamID#/
RegExp=(?siU)<div class="profile_avatar_frame">.*<img src="(.*)">.*</div>.*<img src="(.*)">.*</div>
UpdateRate=300

[MeasureFrame]
Measure=WebParser
URL=[MeasureSteam]
StringIndex=1
Download=1

[MeasureSteamProfile]
Measure=WebParser
URL=[MeasureSteam]
StringIndex=2
Download=1

; Games

[MeasureGame1ID]
Measure=WebParser
URL=[MeasureAll]
StringIndex=1

[MeasureGame1ImageURL]
Measure=WebParser
URL=[MeasureAll]
StringIndex=2
Substitute="\/":"/"

[MeasureGame1ImageDL]
Measure=WebParser
URL=[&MeasureGame1ImageURL]
DynamicVariables=1
Download=1

[MeasureGame2ID]
Measure=WebParser
URL=[MeasureAll]
StringIndex=3

[MeasureGame2ImageURL]
Measure=WebParser
URL=[MeasureAll]
StringIndex=4
Substitute="\/":"/"

[MeasureGame2ImageDL]
Measure=WebParser
URL=[&MeasureGame2ImageURL]
DynamicVariables=1
Download=1

[MeasureGame3ID]
Measure=WebParser
URL=[MeasureAll]
StringIndex=5

[MeasureGame3ImageURL]
Measure=WebParser
URL=[MeasureAll]
StringIndex=6
Substitute="\/":"/"

[MeasureGame3ImageDL]
Measure=WebParser
URL=[&MeasureGame3ImageURL]
DynamicVariables=1
Download=1

[MeasureGame4ID]
Measure=WebParser
URL=[MeasureAll]
StringIndex=7

[MeasureGame4ImageURL]
Measure=WebParser
URL=[MeasureAll]
StringIndex=8
Substitute="\/":"/"

[MeasureGame4ImageDL]
Measure=WebParser
URL=[&MeasureGame4ImageURL]
DynamicVariables=1
Download=1

[MeasureGame5ID]
Measure=WebParser
URL=[MeasureAll]
StringIndex=9

[MeasureGame5ImageURL]
Measure=WebParser
URL=[MeasureAll]
StringIndex=10
Substitute="\/":"/"

[MeasureGame5ImageDL]
Measure=WebParser
URL=[&MeasureGame5ImageURL]
DynamicVariables=1
Download=1

; Images

[MeterPanel]
Meter=Image
MeasureName=MeasureSteamProfile
X=0
Y=0
W=#Height#
H=#Height#
Padding=12,12,(#ToggleVar# = 1 ? 12 : 821),12
SolidColor=#colorskin#,#opacity#
AntiAlias=1
MouseOverAction=[!SetOption #CURRENTSECTION# SolidColor #colorskin2#,#opacity#][!UpdateMeter MeterPanel][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# SolidColor #colorskin#,#opacity#][!UpdateMeter MeterPanel][!Redraw]
DynamicVariables=1
LeftMouseUpAction=[!SetVariable ToggleVar (1-#ToggleVar#)][!UpdateMeter MeterPanel][!Redraw][!ToggleMeter MeterGame1Image][!ToggleMeter MeterGame2Image][!ToggleMeter MeterGame3Image][!ToggleMeter MeterGame4Image][!ToggleMeter MeterGame5Image][!ToggleMeter MeterSteamImage][!UpdateMeter *][!Redraw]

[MeterGame1Image]
Meter=Image
MeasureName=MeasureGame1ImageDL
X=(#Height#+24)
Y=12
W=#Width#
H=#Height#
SolidColor=0,0,0,1
Solid=1
AntiAlias=1
LeftMouseDownAction=steam://rungameid/[MeasureGame1ID]
LeftMouseUpAction=[!EnableMeasure "Timer"][!SetVariable ToggleVar 1]
DynamicVariables=1

[MeterGame2Image]
Meter=Image
MeasureName=MeasureGame2ImageDL
X=0R
Y=12
W=#Width#
H=#Height#
SolidColor=0,0,0,1
Solid=1
AntiAlias=1
LeftMouseDownAction=steam://rungameid/[MeasureGame2ID]
LeftMouseUpAction=[!EnableMeasure "Timer"][!SetVariable ToggleVar 1]
DynamicVariables=1

[MeterGame3Image]
Meter=Image
MeasureName=MeasureGame3ImageDL
X=0R
Y=12
W=#Width#
H=#Height#
SolidColor=0,0,0,1
Solid=1
AntiAlias=1
LeftMouseDownAction=steam://rungameid/[MeasureGame3ID]
LeftMouseUpAction=[!EnableMeasure "Timer"][!SetVariable ToggleVar 1]
DynamicVariables=1

[MeterGame4Image]
Meter=Image
MeasureName=MeasureGame4ImageDL
X=0R
Y=12
W=#Width#
H=#Height#
SolidColor=0,0,0,1
Solid=1
AntiAlias=1
LeftMouseDownAction=steam://rungameid/[MeasureGame4ID]
LeftMouseUpAction=[!EnableMeasure "Timer"][!SetVariable ToggleVar 1]
DynamicVariables=1

[MeterGame5Image]
Meter=Image
MeasureName=MeasureGame5ImageDL
X=0R
Y=12
W=#Width#
H=#Height#
SolidColor=0,0,0,1
Solid=1
AntiAlias=1
LeftMouseDownAction=steam://rungameid/[MeasureGame5ID]
LeftMouseUpAction=[!EnableMeasure "Timer"][!SetVariable ToggleVar 1]
DynamicVariables=1

[MeterSteamImage]
Meter=Image
ImageName=@Resources\Steam.png
X=(0+12)R
Y=12
W=#Height#
H=#Height#
SolidColor=0,0,0,1
Solid=1
AntiAlias=1
LeftMouseDownAction=!Execute ["D:\Program Files (x86)\Steam\Steam.exe"]
LeftMouseUpAction=[!EnableMeasure "Timer"][!SetVariable ToggleVar 1][!UpdateMeter *][!Redraw]

MiddleMouseDownAction=!Execute ["D:\Program Files (x86)\Steam\Steam.exe"][steam://url/SteamIDMyProfile][!EnableMeasure "Timer"][!SetVariable ToggleVar 1][!UpdateMeter *][!Redraw]

RightMouseDownAction=!Execute ["D:\Program Files (x86)\Steam\Steam.exe"][steam://open/games][!EnableMeasure "Timer"][!SetVariable ToggleVar 1][!UpdateMeter *][!Redraw]


DynamicVariables=1

[MeterFrame]
Meter=Image
MeasureName=MeasureFrame
X=7
Y=7
W=(#Height# + 10)
H=(#Height# + 10)
SolidColor=0,0,0,1
Solid=1
AntiAlias=1

[MeterNumOfOcc]
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=#NbGames#
DynamicVariables=1
You do not have the required permissions to view the files attached to this post.
Last edited by Missing on July 29th, 2022, 8:02 pm, edited 2 times in total.
User avatar
Missing
Posts: 4
Joined: July 28th, 2022, 8:28 pm

Re: Webparser shows value 0 with lua scripting

Post by Missing »

Is there anyone that could help?
Let me know if my post is unclear or some information is missing.
User avatar
SilverAzide
Rainmeter Sage
Posts: 1973
Joined: March 23rd, 2015, 5:26 pm

Re: Webparser shows value 0 with lua scripting

Post by SilverAzide »

Missing wrote: July 29th, 2022, 2:33 pm Is there anyone that could help?
Let me know if my post is unclear or some information is missing.
I didn't dig into your question, but one thing that jumps out at me is the variable you have declared:

Code: Select all

NbGames=(?siU)[&MeasureLuaScript:Update()]
My guess is that when Rainmeter first loads, it is going to try to resolve the measure, which is going to return nothing. You'll probably end up with a string of "(?siU)0" or "(?siU)" some such. you can check the About > Skins tab to see.

I hate to say this, and hopefully I'm incorrect, but I suspect your entire approach is wrong. You don't need Lua for one thing; you need a regex that uses look-ahead assertions so you can grab as many values as you want without worrying in advance if they exist in the data or not.

Don't forget that Rainmeter's WebParser is running asynchronously, so there will be a delay between when the data comes back from the website. The skin will already be loaded and visible long before the data returns and you can do something with it.
Gadgets Wiki GitHub More Gadgets...
User avatar
balala
Rainmeter Sage
Posts: 14469
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Webparser shows value 0 with lua scripting

Post by balala »

Missing wrote: July 28th, 2022, 8:56 pm Hello,
I have been working on a skin that takes the recently played games on your steam profile and can launch them from their icon on the skin.
The problem with the skin is that it won't show any games if you have less than 5 games in recent (I decided that the max nb of games shown would be 5).
On my measure that gets the ID and the logo of each games, I copied appid":(.*),.*logo":"(.*)",.* 5 times as the RegExp, for the number of games I want to get. If I had 4 games, then I would simply need to copy it 4 times for the skin to work. However, I'd like it to be user friendly.

To counter this problem, I wrote a small LuaScript that counts the number of games in recent with the number of appearance of "Appid". With the result of that count, I create a sequence of appid":(.*),.*logo":"(.*)",.* with the length needed. This result would then be sent to my skin as a variable and this variable it used for my RegExp. On paper it works...
I'm not sure you need to do this. Instead of counting the number of repetitions and create / set the RegExp accordingly, I better probably would use the Lookahead assertion, to get the appropriate string if it exists, or null if it doesn't. For this instead of repetition of the appid":(.*),.*logo":"(.*)", string in the RegExp, I probably would try the following option: RegExp=appid":(.*),.*logo":"(.*)",.*(?(?=.*appid).*":(.*),.*logo":"(.*)",).*(?(?=.*appid).*":(.*),.*logo":"(.*)",).* .... If the appid":(.*),.*logo":"(.*)", string is present at list once in the value returned by the measure, for the upcoming strings the appropriate child measures will return the got string (if it exist), or remain empty if it doesn't exist.
Please remove the Script measure, modify the RegExp option of the [MeasureAll] measure and try to see if it is working. Does it?
User avatar
Missing
Posts: 4
Joined: July 28th, 2022, 8:28 pm

Re: Webparser shows value 0 with lua scripting

Post by Missing »

balala wrote: July 29th, 2022, 5:07 pm I'm not sure you need to do this. Instead of counting the number of repetitions and create / set the RegExp accordingly, I better probably would use the Lookahead assertion, to get the appropriate string if it exists, or null if it doesn't. For this instead of repetition of the appid":(.*),.*logo":"(.*)", string in the RegExp, I probably would try the following option: RegExp=appid":(.*),.*logo":"(.*)",.*(?(?=.*appid).*":(.*),.*logo":"(.*)",).*(?(?=.*appid).*":(.*),.*logo":"(.*)",).* .... If the appid":(.*),.*logo":"(.*)", string is present at list once in the value returned by the measure, for the upcoming strings the appropriate child measures will return the got string (if it exist), or remain empty if it doesn't exist.
Please remove the Script measure, modify the RegExp option of the [MeasureAll] measure and try to see if it is working. Does it?
Image

It seems to be partially working. It does work even if not all results are found. However, for some reason it captures twice the first appid and every other appid after that are shifted and doesn't show the right result.
Image
The pictures seems to be working fine though.

I don't know why the appid part isn't working.
User avatar
Missing
Posts: 4
Joined: July 28th, 2022, 8:28 pm

Re: Webparser shows value 0 with lua scripting

Post by Missing »

Missing wrote: July 29th, 2022, 6:46 pm Image

It seems to be partially working. It does work even if not all results are found. However, for some reason it captures twice the first appid and every other appid after that are shifted and doesn't show the right result.
Image
The pictures seems to be working fine though.

I don't know why the appid part isn't working.
I think I got it. My range was to vague so it was looking at everything between ": and , (which there was a lot of possible result.
I have changed it to

Code: Select all

(?(?=.*appid).*appid":(.*),".*logo":"(.*)",).*
and it seems to be working fine.

Thank you for your answers, I didn't know about Lookahead Assertions, that would have saved me a lot of time. I should be good for the rest!
User avatar
balala
Rainmeter Sage
Posts: 14469
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Webparser shows value 0 with lua scripting

Post by balala »

Missing wrote: July 29th, 2022, 6:56 pm I think I got it. My range was to vague so it was looking at everything between ": and , (which there was a lot of possible result.
I have changed it to

Code: Select all

(?(?=.*appid).*appid":(.*),".*logo":"(.*)",).*
and it seems to be working fine.
Great, I'm glad. :thumbup:
Missing wrote: July 29th, 2022, 6:56 pm I didn't know about Lookahead Assertions, that would have saved me a lot of time.
Right, in many cases the Lookahead assertion is a great feature, which may be extremely useful.