Search code examples
regexparsingpcreskinrainmeter

Get badges information with Rainmeter webparser


I'm trying to do a skin for Rainmeter which display reputation score and number of badges from an user profile page. Everything works great if the user have at least one badge from each category (gold, silver, bronze), but in my case for example, I don't have any gold badges yet and the skin looks something like enter image description here. The desired output will be something like Stack Overflow 401 0 1 7. My actual code is the following.

[Rainmeter]
Author=Dragos Sandu
Update=1000
DynamicWindowSize=1

[Metadata]
Name=Stack Overflow Stats
Author=Dragos Sandu
Version=28 March 2015 rev 1
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
Information=Simple stats displaying for Stack Overflow

[Variables]
FontName=Trebuchet MS
FontSize=12

[MeasureAll]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=http://stackoverflow.com/users/2691507/dragos-sandu
RegExp=(?siU)<span class="reputation-score">(.*)</span>.*<span class="badgecount">(.*)</span>.*<span class="badgecount">(.*)</span>.*<span class="badgecount">(.*)</span>

[MeasureReputation]
Measure=Plugin
Plugin=WebParser
URL=[MeasureAll]
StringIndex=1

[MeasureGold]
Measure=Plugin
Plugin=WebParser
URL=[MeasureAll]
StringIndex=2

[MeasureSilver]
Measure=Plugin
Plugin=WebParser
URL=[MeasureAll]
StringIndex=3

[MeasureBronze]
Measure=Plugin
Plugin=WebParser
URL=[MeasureAll]
StringIndex=4

[MeterText]
Meter=String
Prefix="Stack Overflow  "
FontFace=#FontName#
FontColor=#FFF
FontSize=#FontSize#
StringAlign=Left

[MeterReputation]
Meter=String
MeasureName=MeasureReputation
FontFace=#FontName#
FontColor=F0F0F0
FontSize=#FontSize#
StringAlign=Left
StringStyle=bold
X=120

[MeterGold]
Meter=String
MeasureName=MeasureGold
X=195
FontFace=#FontName#
FontColor=FFCC00
FontSize=#FontSize#
StringStyle=bold
StringAlign=Left

[MeterSilver]
Meter=String
MeasureName=MeasureSilver
X=235
FontFace=#FontName#
FontColor=C5C5C5
FontSize=#FontSize#
StringStyle=bold
StringAlign=Left

[MeterBronze]
Meter=String
MeasureName=MeasureBronze
X=285
FontFace=#FontName#
FontColor=CC9966
FontSize=#FontSize#
StringStyle=bold
StringAlign=Left

I read something about Webparser Lookahead Assertions and try to do a working RegExp but with no success. The best result I had was (?siU)<span class="reputation-score">(.*)</span>(?(?=.*<span title="(.*) gold))(?(?=.*<span title="(.*) silver))(?(?=.*<span title="(.*) bronze)) but it didn't provide what i want. What should be the correct RegExp? Thanks!


Solution

  • I had given up with this little project, but today I finally succeed. Stackoverflow has recently changed his look a bit and his classes and HTML too. So, now I was able to parse the desire information using the Lookahead Assertions method metion in the Rainmeter docs. For everyone who it's interested I will post my working RegExp below. Also, a link to entire Rainmeter Skin will be available soon.

    RegExp=(?siU)<div class="reputation" title="reputation">(.*)<span.*(?(?=.*class="badge1-alternate").*<span class="badge1"></span><span class="badgecount">(.*)</span></span>).*(?(?=.*class="badge2-alternate").*<span class="badge2"></span><span class="badgecount">(.*)</span></span>).*(?(?=.*class="badge3-alternate").*<span class="badge3"></span><span class="badgecount">(.*)</span></span>)