It is currently April 18th, 2024, 9:53 am

[solved] noob: wanna retrieve web data with lua

Get help with creating, editing & fixing problems with skins
Decors
Posts: 7
Joined: June 26th, 2017, 8:02 am

[solved] noob: wanna retrieve web data with lua

Post by Decors »

Sorry my bad english.

I've just started rainmeter today and been trying to retrieve web data by using webparse....but I can't handle still.
Some one please tell me most simple sample code to retrieve this data below. (with lua cause I only know lua :/)
Just simple one that store retrieved data to variable.

Thanks in advance.

sample data I wanna retrieve (in game ladder information)
*link*
--- start
{"total":15000,"entries":[{"rank":1,"dead":false,"online":false,"character":{"name":"onePorcupine_and_im_die","level":92,"class":"Elementalist","experience":2278967597},"account":{"name":"Axwell95","challenges":{"total":22}}},{"rank":2,"dead":false,"online":true,"character":{"name":"XxXTriHardXxX","level":89,"class":"Gladiator","experience":1920696937},"account":{"name":"AlkaizerX","challenges":{"total":20}}},{"rank":3,"dead":false,"online":false,"character":{"name":"me_bobo_u_no_bobodalpat","level":89,"class":"Champion","experience":1844370970},"account":{"name":"banshoon","challenges":{"total":15},"twitch":{"name":"me_bobo"}}}]}
---- end
Last edited by Decors on June 29th, 2017, 4:27 am, edited 1 time in total.
Decors
Posts: 7
Joined: June 26th, 2017, 8:02 am

Re: noob: wanna retrieve web data with lua

Post by Decors »

i already made a few for you .... the first 3 items ... you have to make the rest of the 25 your self...
Wonderful.
I was just trying something with your first post and at least got one data "15000" lol.
I didn't know we have to set all parameter to regexp.Also have to set all childs!!
Tough stuff but I gonna try your sample.

thanks!
Decors
Posts: 7
Joined: June 26th, 2017, 8:02 am

Re: noob: wanna retrieve web data with lua

Post by Decors »

I've been trying to edit retrieved data via lua script but my script doesn't work well.
Finally I retrieved data what I want into lua but I can't edit those data.
Foe example, my gsub searching for rainmeter "variable name" but "value".
I wanna gsub retrieved data by lua script.

thx

my test scripts

Code: Select all

[Rainmeter]
Update=1000

[MeasureLuaScript]
Measure=Script
ScriptFile="#CURRENTPATH#skintest.lua"

[TextStyle]
FontFace=Segoe UI
FontColor=255,255,255,255
SolidColor=0,0,0,1
FontSize=11
StringStyle=Bold
AntiAlias=1

[MeasureRetrieve]
Measure=Plugin
Plugin=WebParser
Url=http://api.pathofexile.com/ladders/2 Week Mayhem HC Solo (JRE093)?limit=3
UpdateRate=60
StringIndex=1
RegExp=(?siU).*entries.*{(.*)}
DecodeCharacterReference=1

[Variables]
RetrievedData=[MeasureRetrieve]

[MeterLabel1]
Meter=String
MeterStyle=styleLeftText
FontColor=#VarColor#
X=10
Y=80
W=20
H=14
Text=A=

[MeterLabel1Value]
Meter=String
MeterStyle=styleRightText
MeasureName=MeasureRetrieve
FontColor=#VarColor#
X=26
Y=80
W=1000
H=14
Text=%1

[MeterLabel2]
Meter=String
MeterStyle=styleLeftText
FontColor=#VarColor#
X=10
Y=100
W=20
H=14
Text=B=

[MeterLabel2Value]
Meter=String
MeterStyle=styleRightText
FontColor=#VarColor#
X=26
Y=100
W=1000
H=14
Text=""
DynamicVariables=1
------Lua------

Code: Select all

function Initialize()
	num = 0
end

function Update()
	num = num+1
	--v = SKIN:GetMeasure("MeasureRetrieve"):GetValue()
	v = SKIN:GetVariable("RetrievedData")
	if num < 5 then
		v = num.."s-string.len["..string.len(v).."]"..v
	else
		v = num.."s-string.len["..string.len(v).."]"..string.gsub(v,"rank","")
	end
	SKIN:Bang("!SetOption MeterLabel2Value Text "..v)
end
Decors
Posts: 7
Joined: June 26th, 2017, 8:02 am

Re: noob: wanna retrieve web data with lua

Post by Decors »

GetStringValue() solved the problem.

SKIN:GetMeasure("MeasureRetrieve"):GetStringValue()

Thank you for the help.

Sample script just FYI.

Code: Select all

[Rainmeter]
Update=1000

[MeasureLuaScript]
Measure=Script
ScriptFile="#CURRENTPATH#skintest.lua"
MeterToSetValue=MeterLabel2Value

[TextStyle]
FontFace=Segoe UI
FontColor=255,255,255,255
SolidColor=0,0,0,1
FontSize=11
StringStyle=Bold
AntiAlias=1

[MeasureRetrieve]
Measure=Plugin
Plugin=WebParser
Url=http://api.pathofexile.com/ladders/2 Week Mayhem HC Solo (JRE093)?limit=3
UpdateRate=60
StringIndex=1
RegExp=(.*)
DecodeCharacterReference=1
;;FinishAction=!CommandMeasure MeasureLuaScript Update()

[MeterLabel1]
Meter=String
MeterStyle=styleLeftText
FontColor=#VarColor#
X=10
Y=80
W=20
H=14
Text=A=

[MeterLabel1Value]
Meter=String
MeterStyle=styleRightText
MeasureName=MeasureRetrieve
FontColor=#VarColor#
X=26
Y=80
W=1000
H=14
Text=%1

[MeterLabel2]
Meter=String
MeterStyle=styleLeftText
FontColor=#VarColor#
X=10
Y=100
W=20
H=14
Text=B=

[MeterLabel2Value]
Meter=String
MeterStyle=styleRightText
FontColor=#VarColor#
X=26
Y=100
W=1000
H=14
Text=""
DynamicVariables=1

Code: Select all

function Initialize()
	num = 0
end

function Update()
	num = num+1
	data = SKIN:GetMeasure("MeasureRetrieve"):GetStringValue()
	data = string.gsub(data,"total.*entries.:","")
	data = string.gsub(data,"rank.:","")
	data = string.gsub(data,"dead.:","")
	data = string.gsub(data,"online.:","")
	data = string.gsub(data,"character.:","")
	data = string.gsub(data,"name.:","")
	data = string.gsub(data,"level.:","")
	data = string.gsub(data,"class.:","")
	data = string.gsub(data,"experience.:","")
	data = string.gsub(data,"account.:","")
	data = string.gsub(data,"challenges.:..total.:[0-9]*","return")
	data = string.gsub(data,"[{}%[%]]","")
	data = num.."s-string.len["..string.len(data).."]"..data
	SKIN:Bang("!SetOption MeterLabel2Value Text "..data)
end