It is currently September 21st, 2019, 5:37 am

[Solved]Counting items

Discuss the use of Lua in Script measures.
User avatar
FreeRaider
Posts: 786
Joined: November 20th, 2012, 11:58 pm

[Solved]Counting items

FreeRaider » October 21st, 2016, 5:47 pm

I'm trying to create a lua files that counts how many "Others" are present in a file, but only if they are in the <span class= "Title">. The problem is that sometimes there is another <span class="Title" etc>, then how do I count only the "Others" under <span class="Title"> if there is or there is not another <span class = "Title" etc>?




skin.ini

Code: Select all

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

[MeasureSite]
Measure=Plugin
Plugin=WebParser
URL=file://#CURRENTPATH#SomeFile.txt
RegExp=(?siU)^(.*)$
UpdateRate=60000
FinishAction=[!UpdateMeasure MeasureScript]

[MeasureScript]
Measure=Script
ScriptFile=count.lua
UpdateDivider=-1

[MeterString]
Meter=String
SomeFile.txt

Code: Select all

<div class="Today">A Name HERE</div><div class="Type" style="padding-top:5px">A TYPE HERE</div>


<span class="Title">A TITLE HERE</span><br /><br />

<span class="Others" style="margin-bottom: 10px;">Name ONE<br /><i style="font-weight:normal;margin-left: 20px;">Type ONE</i></span><br /><span class="Others" style="margin-bottom: 10px;">Name TWO<br /><i style="font-weight:normal;margin-left: 20px;">Type TWO</i></span><br /><span class="Others" style="margin-bottom: 10px;">Name THREE<br /><i style="font-weight:normal;margin-left: 20px;">Type THREE</i></span><br /><span class="Title" style="clear: both;margin-top: 20px;margin-bottom: 20px;">ANOTHER TITLE HERE</span><br /><br />	<span class="Others" style="margin-bottom: 10px;"><a style="float:left" href="DATE">DATE ONE</a><span style="float:left">: </span><span style="float:left; width:370px; margin-left:3px">Name FOUR<br /><i style="font-weight:normal;margin-left: 20px">Type FOUR</i></span></span></span><br /><span class="Others" style="margin-bottom: 10px;"><a style="float:left" href="DATE 2">DATE TWO</a><span style="float:left">: </span><span style="float:left; width:370px; margin-left:3px">Name FIVE<br /><i style="font-weight:normal;margin-left: 20px"></i></span></span></span><br /><br /><br />
count.lua

Code: Select all

function Initialize()

   measureSite = SKIN:GetMeasure('MeasureSite')
   
end

function Update()

   msSite = measureSite:GetStringValue()
   if msSite == '' then return end
     
   dummyString, dataCount = string.gsub(msSite, '<span class="Others".->', '')

   print(dataCount)

end
Last edited by FreeRaider on October 21st, 2016, 8:43 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 8631
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Counting items

balala » October 21st, 2016, 6:43 pm

I'd try something like this:

count.lua:

Code: Select all

function Initialize()
	measureSite = SKIN:GetMeasure('MeasureSite')
end

function Update()
	msSite = measureSite:GetStringValue()
	if msSite == '' then return end
	dummyString, dataCount = string.gsub(msSite, '<span class="Title">'..'.-'..'<span class="Others".->'..'.-'..'</span>', '')
--	print(dataCount)
	SKIN:Bang('!SetVariable', 'Str', dummyString..' / '..dataCount)
end
and skin.ini:

Code: Select all

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

[MeasureSite]
Measure=Plugin
Plugin=WebParser
URL=file://#CURRENTPATH#SomeFile.txt
RegExp=(?siU)^(.*)$
UpdateRate=60000
FinishAction=[!UpdateMeasure MeasureScript]

[MeasureScript]
Measure=Script
ScriptFile=count.lua
UpdateDivider=-1

[MeterString]
Meter=String
X=0
Y=0
W=500
H=800
ClipString=1
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=#Str#
DynamicVariables=1
User avatar
FreeRaider
Posts: 786
Joined: November 20th, 2012, 11:58 pm

Re: Counting items

FreeRaider » October 21st, 2016, 7:26 pm

Thanks babala, but unfortunately it does not work.
User avatar
balala
Rainmeter Sage
Posts: 8631
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Counting items

balala » October 21st, 2016, 7:39 pm

FreeRaider wrote:Thanks babala, but unfortunately it does not work.
I had the impression it works for me. What's not working? Don't get the right number?
User avatar
FreeRaider
Posts: 786
Joined: November 20th, 2012, 11:58 pm

Re: Counting items

FreeRaider » October 21st, 2016, 7:53 pm

in "dataCount" should be only 3 "Others"
User avatar
balala
Rainmeter Sage
Posts: 8631
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Counting items

balala » October 21st, 2016, 8:22 pm

FreeRaider wrote:in "dataCount" should be only 3 "Others"
I misunderstood something? In the original SomeFile.txt, I can't find 3 "Others", which match your criteria. Which ones are those three?
User avatar
FreeRaider
Posts: 786
Joined: November 20th, 2012, 11:58 pm

Re: Counting items

FreeRaider » October 21st, 2016, 8:43 pm

Nevermind babala, i solved

Code: Select all

function Initialize()
   measureSite = SKIN:GetMeasure('MeasureSite')
end

function Update()

   msSite = measureSite:GetStringValue()
   if msSite == '' then return end
   
   msSite2 = string.match(msSite, '<span class="Title">(.-)<span class="Title".->')
   
   dummyString, dataCount = string.gsub(msSite2, '<span class="Others".->', '')
   
   print(dataCount)
   
end
User avatar
balala
Rainmeter Sage
Posts: 8631
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: [Solved]Counting items

balala » October 21st, 2016, 9:03 pm

Ok, I'm glad in this case.