It is currently April 27th, 2024, 12:22 am

Returning a variable number of results with Webparser

Get help with creating, editing & fixing problems with skins
Freshmeat
Posts: 3
Joined: April 2nd, 2010, 6:58 pm

Returning a variable number of results with Webparser

Post by Freshmeat »

Hi, I am making a skin that should show how many players are populating our Killing Floor servers. Request returns following html (relevant part):

Code: Select all

</tr>
           <tr><td class="nabg">X-Storm</td><td class="text" align="center">23</td><!-- if _RO_ --><td class="text" align="center">0.00</td><!-- end _RO_ --><td class="text" align="center">0.00</td><td class="text" align="center">0</td><!-- if _RO_ <td class="text" align="center"><%Sprees%></td><td class="text" align="center"><%MultiKills%></td> end _RO_ --></tr>
<tr><td class="nabg">CrellerFTW</td><td class="text" align="center">16</td><!-- if _RO_ --><td class="text" align="center">0.00</td><!-- end _RO_ --><td class="text" align="center">1.00</td><td class="text" align="center">1</td><!-- if _RO_ <td class="text" align="center"><%Sprees%></td><td class="text" align="center"><%MultiKills%></td> end _RO_ --></tr>

This block may contain up to six lines instead of two. Is there a way to make Rainmeter handle displaying the players names, no matter how many there are?

I have been trying

Code: Select all

[MeasureWebsite]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1800
Url=#URL#
RegExp="(?siU)<tr><td class="nabg">(.*)</td>
Debug=1

[MeasureIPAddress]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWebsite]
StringIndex=1

[MeasureCountryCode]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWebsite]
StringIndex=2

[MeasureCountryName]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWebsite]
StringIndex=3

[MeasureRegionCode]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWebsite]
StringIndex=4

[MeasureRegionName]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWebsite]
StringIndex=5

[MeasureCityCode]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWebsite]
StringIndex=6



;[DISPLAY METERS]==================================

[MeterBackground]
Meter=IMAGE
X=1
Y=1
H=220
W=300
SolidColor=0,0,0,255

[MeterIPAddress]
MeasureName=MeasureIPAddress
Meter=STRING
X=2
Y=2
FontColor=#FontColor#
FontSize=12
StringAlign=LEFT
FontFace=#FontFace#
Antialias=1
Prefix="IP Address: "

[MeterCountryCode]
MeasureName=MeasureCountryCode
Meter=STRING
X=2
Y=17r
FontColor=#FontColor#
FontSize=12
StringAlign=LEFT
FontFace=#FontFace#
Antialias=1
Prefix="Country Code: "

[MeterCountryName]
MeasureName=MeasureCountryName
Meter=STRING
X=2
Y=17r
FontColor=#FontColor#
FontSize=12
StringAlign=LEFT
FontFace=#FontFace#
Antialias=1
Prefix="Country Name: "

[MeterRegionCode]
MeasureName=MeasureRegionCode
Meter=STRING
X=2
Y=17r
FontColor=#FontColor#
FontSize=12
StringAlign=LEFT
FontFace=#FontFace#
Antialias=1
Prefix="Region Code: "

[MeterRegionName]
MeasureName=MeasureRegionName
Meter=STRING
X=2
Y=17r
FontColor=#FontColor#
FontSize=12
StringAlign=LEFT
FontFace=#FontFace#
Antialias=1
Prefix="Region/State: "

[MeterCityCode]
MeasureName=MeasureCityCode
Meter=STRING
X=2
Y=17r
FontColor=#FontColor#
FontSize=12
StringAlign=LEFT
FontFace=#FontFace#
Antialias=1
Prefix="City Code: "
By cut and paste from the tutorial. It works with RainRegxps, but gives an error when I run it live (code: -1)

Thanks in advance,

-Freshmeat
User avatar
maminscris
Posts: 509
Joined: April 24th, 2009, 3:17 pm
Location: Bucharest, Romania Lat 44,43° Lon 26,1°

Re: Returning a variable number of results with Webparser

Post by maminscris »

RegExp="(?siU)<tr><td class="nabg">(.*)</td>

try to delete <tr> or RegExp="(?siU)<tr>.*<td class="nabg">(.*)</td>
Zero at programing, zero at writing codes, so far 2 at making images
But I'm good at copy/paste, and I not always like this
Image
User avatar
JamesAC
Developer
Posts: 318
Joined: July 14th, 2009, 5:57 pm

Re: Returning a variable number of results with Webparser

Post by JamesAC »

Try this:

Code: Select all

RegExp=(?siU)(?:<tr><td class="nabg">(.*)</td>)(?:<tr><td class="nabg">(.*)</td>)(?:<tr><td class="nabg">(.*)</td>)(?:<tr><td class="nabg">(.*)</td>)(?:<tr><td class="nabg">(.*)</td>)(?:<tr><td class="nabg">(.*)</td>)
I hanvt tested it in rainmeter but it might work
+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
Quis custodiet ipsos custodes?
Freshmeat
Posts: 3
Joined: April 2nd, 2010, 6:58 pm

Re: Returning a variable number of results with Webparser

Post by Freshmeat »

I tried both, but it did not work.

Another complication is that the regexp can return zero hits as well. So I might rephrase the problem:

I need to have Regexp to return 0 - 6 hits, and a way to handle the empty indices that result when Regexp return fewer than 6 hits. Then I can always tune the search strings to give the correct answers.

Come to think of it, It might be possible to do with ungreedy searching to filter out each result until none are left, and use Errorstring when none are left.

EDIT: First version work and gives one hit if I remember to add the last ". However, it does not return multiple hits. Second one stil fails.
User avatar
kenz0
Developer
Posts: 263
Joined: July 31st, 2009, 2:23 pm
Location: Tokyo, JPN

Re: Returning a variable number of results with Webparser

Post by kenz0 »

This RegExp pattern allows 0 -6 results. If 6 results exist, 6 results will be returned, and only 3 results will be returned if only 3 results exist. If it is empty, null is returned then it is replaced with "n/a" by Substitute.

Code: Select all

[Measure1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1800
Url=#URL#
RegExp="(?siU)(?:.*class="nabg">(.*)<|)(?:.*class="nabg">(.*)<|)(?:.*class="nabg">(.*)<|)(?:.*class="nabg">(.*)<|)(?:.*class="nabg">(.*)<|)(?:.*class="nabg">(.*)<|)"
StringIndex=1
Substitute="":"n/a"

[Measure2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[Measure1]
StringIndex=2
Substitute="":"n/a"

[Measure3]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[Measure1]
StringIndex=3
Substitute="":"n/a"

[Measure4]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[Measure1]
StringIndex=4
Substitute="":"n/a"

[Measure5]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[Measure1]
StringIndex=5
Substitute="":"n/a"

[Measure6]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[Measure1]
StringIndex=6
Substitute="":"n/a"
.
Image
Freshmeat
Posts: 3
Joined: April 2nd, 2010, 6:58 pm

Re: Returning a variable number of results with Webparser

Post by Freshmeat »

Works like a charm, thanks a lot.

-Freshmeat (Who needs to read seriously on Regexp)