It is currently April 20th, 2024, 4:23 am

Facebook and Rainmeter

Get help with creating, editing & fixing problems with skins
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Facebook and Rainmeter

Post by FreeRaider »

A solution using a lua script:

code.ini

Code: Select all

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

[MeasureFacebook]
Measure=Plugin
Plugin=WebParser
Url=https://www.facebook.com/BFMTV/likes
UpdateRate=300
RegExp=(?siU).*\["PagesLikesTab",.*elem_.*\}.*\],(.*)\],\[\]\],
FinishAction=[!EnableMeasure MeasureLikes][!UpdateMeasure MeasureLikes][!EnableMeasure MeasureScript][!UpdateMeasure MeasureScript][!ShowMeter MeterValueFacebook]

[MeasureLikes]
Measure=Plugin
Plugin=WebParser
URL=[MeasureFacebook]
StringIndex=1
RegExpSubstitute=1
Substitute="^$":"..."
Disabled=1

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

[MeterValueFacebook]
Meter=String
MeasureName=MeasureScript
X=10
Y=10
W=190
H=100
FontColor=220,220,220
FontSize=15
FontFace=Calibri
StringStyle=BOLD
LeftMouseUpAction=["https://www.facebook.com/BFMTV/likes"]
Text=%1 likes
AntiAlias=1
Hidden=1


spacebetweendigits.lua

Code: Select all

function Initialize()

    numbers_likes = SKIN:GetMeasure('MeasureLikes')
    
	
end

function Update()
	
	number = numbers_likes:GetStringValue()
	
	return space_value(number)
		
end



function space_value(num)
  local formatted = num
  while true do  
    formatted, triplet = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1 %2')
    if (triplet==0) then
      break
    end
  end
  return formatted
end
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Facebook and Rainmeter

Post by balala »

FreeRaider wrote:balala, a note: if the number is not composed of 7 digits, it does not make the substitution.

I think it's better to use a lua script.
In fact my initial code does the substitution for any number which has 7, 8 or 9 digits.
The lua solution for sure is a very good one, but something similar can be achieved even without a lua script. Just in case anyone would like to see what I'm talking about:

Code: Select all

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

[MeasureFacebook]
Measure=Plugin
Plugin=WebParser
Url=https://www.facebook.com/BFMTV/likes
UpdateRate=300
RegExp=(?siU).*\["PagesLikesTab",.*elem_.*\}.*\],(.*)\],\[\]\],
FinishAction=[!EnableMeasure MeasureLikes][!UpdateMeasure MeasureLikes]

[MeasureLikes]
Measure=Plugin
Plugin=WebParser
URL=[MeasureFacebook]
StringIndex=1
IfCondition=(MeasureLikes<=999)
IfTrueAction=[!SetVariable Subst ""][!SetVariable Subst2 ""][!UpdateMeasure "MeasureLikesGrouped"][!UpdateMeter MeterValueFacebook][!ShowMeter MeterValueFacebook][!Redraw]
IfCondition2=((MeasureLikes>999)&&(MeasureLikes<=999999))
IfTrueAction2=[!SetVariable Subst "(\d{0,3})(\d{3})"][!SetVariable Subst2 "\1 \2"][!UpdateMeasure "MeasureLikesGrouped"][!UpdateMeter MeterValueFacebook][!ShowMeter MeterValueFacebook][!Redraw]
IfCondition3=((MeasureLikes>999999)&&(MeasureLikes<=999999999))
IfTrueAction3=[!SetVariable Subst "(\d{0,3})(\d{3})(\d{3})"][!SetVariable Subst2 "\1 \2 \3"][!UpdateMeasure "MeasureLikesGrouped"][!UpdateMeter MeterValueFacebook][!ShowMeter MeterValueFacebook][!Redraw]
IfCondition4=((MeasureLikes>999999999)&&(MeasureLikes<=999999999999))
IfTrueAction4=[!SetVariable Subst "(\d{0,3})(\d{3})(\d{3})(\d{3})"][!SetVariable Subst2 "\1 \2 \3 \4"][!UpdateMeasure "MeasureLikesGrouped"][!UpdateMeter MeterValueFacebook][!ShowMeter MeterValueFacebook][!Redraw]
IfCondition5=((MeasureLikes>999999999999)&&(MeasureLikes<=999999999999999))
IfTrueAction5=[!SetVariable Subst "(\d{0,3})(\d{3})(\d{3})(\d{3})(\d{3})"][!SetVariable Subst2 "\1 \2 \3 \4 \5"][!UpdateMeasure "MeasureLikesGrouped"][!UpdateMeter MeterValueFacebook][!ShowMeter MeterValueFacebook][!Redraw]
IfCondition6=((MeasureLikes>999999999999999)&&(MeasureLikes<=999999999999999999))
IfTrueAction6=[!SetVariable Subst "(\d{0,3})(\d{3})(\d{3})(\d{3})(\d{3})(\d{3})"][!SetVariable Subst2 "\1 \2 \3 \4 \5 \6"][!UpdateMeasure "MeasureLikesGrouped"][!UpdateMeter MeterValueFacebook][!ShowMeter MeterValueFacebook][!Redraw]
Disabled=1

[MeasureLikesGrouped]
Measure=String
String=[MeasureLikes]
RegExpSubstitute=1
Substitute="#Subst#":"#Subst2#"
DynamicVariables=1

[MeterValueFacebook]
Meter=String
MeasureName=MeasureLikesGrouped
X=10
Y=10
W=190
H=100
FontColor=220,220,220
FontSize=15
FontFace=Calibri
StringStyle=BOLD
LeftMouseUpAction=["https://www.facebook.com/BFMTV/likes"]
Text=%1 likes
AntiAlias=1
Hidden=1
This code will work for any number up to 999,999,999,999,999,999, but adding further IfConditions / IfTrueActions to the [MeasureLikes] measure, this limit can be easily extended.
Again FreeRaider, I don't want to underestimate your solution. Mine is just another way to achieve the same thing.
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Facebook and Rainmeter

Post by FreeRaider »

OFF TOPIC

balala wrote:Again FreeRaider, I don't want to underestimate your solution. Mine is just another way to achieve the same thing.
Oh not, not. Don't worry balala. I appreciate this exchange of views.

Sometimes, my mind can not find the simplest solution, but instead it finds the most complicated.

Anyway, another thing learned.

Thank you so much.
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Facebook and Rainmeter

Post by balala »

FreeRaider wrote:Oh not, not. Don't worry balala. I appreciate this exchange of views.

Sometimes, my mind can not find the simplest solution, but instead it finds the most complicated.

Anyway, another thing learned.

Thank you so much.
You're welcome. And I also appreciate your lua code, it was interesting to study it. Against my code, it has the advantage that has no upper limit, which in the Rainmeter code exists (even if it's large enough).
And you're right, with Rainmeter (and lua) there's always something to learn.
PtitChat107
Posts: 126
Joined: December 31st, 2015, 6:40 pm

Re: Facebook and Rainmeter

Post by PtitChat107 »

Sorry for not being able to meet you earlier but thank you very much for your help, I allowed myself preferred the idea of ​​Balala regarding the formatting of the captured figure but it remains to implement the same system for a youtube account and it will be perfect ( Balala, if you are motivated to help me :p ) .
Thanks again !
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Facebook and Rainmeter

Post by balala »

PtitChat107 wrote:Sorry for not being able to meet you earlier but thank you very much for your help, I allowed myself preferred the idea of ​​Balala regarding the formatting of the captured figure but it remains to implement the same system for a youtube account and it will be perfect ( Balala, if you are motivated to help me :p ) .
Thanks again !
I am (or at least will be).
Do you have any code so far, for the YouTube? What's the question about it?
PtitChat107
Posts: 126
Joined: December 31st, 2015, 6:40 pm

Re: Facebook and Rainmeter

Post by PtitChat107 »

balala wrote:Do you have any code so far, for the YouTube?
I counted back what you had already coded on the recovered text formatting but I just realized that I did not really need.
That's basically what I wanted to do:
[measureYouTube]
Measure=Plugin
Plugin=WebParser
Url=https://www.youtube.com/user/joueurdugrenier
UpdateRate=60
StringIndex=1
RegExp="(?siU).*<span aria-labelledby="yt-uix-tooltip594-arialabel" data-tooltip-text="2&nbsp;710&nbsp;936" class="yt-subscription-button-subscriber-count-branded-horizontal subscribed yt-uix-tooltip" title="2&nbsp;710&nbsp;936" tabindex="0" aria-label="2&nbsp;710&nbsp;936&nbsp;abonnés">(.*)</span>.*"
Substitute="":"..."
DecodeCharacterReference=1


[meterLabelYouTube]
Meter=String
MeterStyle=styleLeftText
X=10
Y=80
W=190
H=14
Text=Youtube subscribers :
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Facebook and Rainmeter

Post by balala »

PtitChat107 wrote:I counted back what you had already coded on the recovered text formatting but I just realized that I did not really need.
That's basically what I wanted to do:
Sorry, but using your code, I can't get anything. I rewrote a few things, please give a try to the following code and let me know if it get the desired number (if I'm not wrong, right now it is 1,775,220). For now, the code don't format the got number, first I'd like to know if that's what you need.
The code of the WebParser measure:

Code: Select all

[measureYouTube]
Measure=Plugin
Plugin=WebParser
Url=https://www.youtube.com/user/joueurdugrenier
UpdateRate=60
StringIndex=1
RegExp=(?siU)view_count":"(.*)"
Substitute="":"..."
DecodeCharacterReference=1
PtitChat107
Posts: 126
Joined: December 31st, 2015, 6:40 pm

Re: Facebook and Rainmeter

Post by PtitChat107 »

[quote="balala"]Sorry, but using your code, I can't get anything. I rewrote a few things, please give a try to the following code and let me know if it get the desired number (if I'm not wrong, right now it is 1,775,220). For now, the code don't format the got number, first I'd like to know if that's what you need.[quote]

I speak of the number which is currently 2,711,104.
I relied on the format directly back what you had to give me before:

Code: Select all

[MeasureLikes]
Measure=Plugin
Plugin=WebParser
URL=[MeasureFacebook]
StringIndex=1
IfCondition=(MeasureLikes<=999)
IfTrueAction=[!SetVariable Subst ""][!SetVariable Subst2 ""][!UpdateMeasure "MeasureLikesGrouped"][!UpdateMeter MeterValueFacebook][!ShowMeter MeterValueFacebook][!Redraw]
IfCondition2=((MeasureLikes>999)&&(MeasureLikes<=999999))
IfTrueAction2=[!SetVariable Subst "(\d{0,3})(\d{3})"][!SetVariable Subst2 "\1 \2"][!UpdateMeasure "MeasureLikesGrouped"][!UpdateMeter MeterValueFacebook][!ShowMeter MeterValueFacebook][!Redraw]
IfCondition3=((MeasureLikes>999999)&&(MeasureLikes<=999999999))
IfTrueAction3=[!SetVariable Subst "(\d{0,3})(\d{3})(\d{3})"][!SetVariable Subst2 "\1 \2 \3"][!UpdateMeasure "MeasureLikesGrouped"][!UpdateMeter MeterValueFacebook][!ShowMeter MeterValueFacebook][!Redraw]
IfCondition4=((MeasureLikes>999999999)&&(MeasureLikes<=999999999999))
IfTrueAction4=[!SetVariable Subst "(\d{0,3})(\d{3})(\d{3})(\d{3})"][!SetVariable Subst2 "\1 \2 \3 \4"][!UpdateMeasure "MeasureLikesGrouped"][!UpdateMeter MeterValueFacebook][!ShowMeter MeterValueFacebook][!Redraw]
IfCondition5=((MeasureLikes>999999999999)&&(MeasureLikes<=999999999999999))
IfTrueAction5=[!SetVariable Subst "(\d{0,3})(\d{3})(\d{3})(\d{3})(\d{3})"][!SetVariable Subst2 "\1 \2 \3 \4 \5"][!UpdateMeasure "MeasureLikesGrouped"][!UpdateMeter MeterValueFacebook][!ShowMeter MeterValueFacebook][!Redraw]
IfCondition6=((MeasureLikes>999999999999999)&&(MeasureLikes<=999999999999999999))
IfTrueAction6=[!SetVariable Subst "(\d{0,3})(\d{3})(\d{3})(\d{3})(\d{3})(\d{3})"][!SetVariable Subst2 "\1 \2 \3 \4 \5 \6"][!UpdateMeasure "MeasureLikesGrouped"][!UpdateMeter MeterValueFacebook][!ShowMeter MeterValueFacebook][!Redraw]
Disabled=1
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Facebook and Rainmeter

Post by balala »

PtitChat107 wrote:I speak of the number which is currently 2,711,104.
I relied on the format directly back what you had to give me before:
Ok, so if I'm not wrong you succeeded to get that number. Am I right?
Let's say the [MeasureYouTube] is the parent WebParser measure. Its child measure is [MeasureSub], which will return the ungrouped number. I don't included the whole code of the parent measure, because (again if I'm not wrong), you have it, but be careful, to not forget its finishAction option:

Code: Select all

[MeasureYouTube]
Measure=Plugin
Plugin=WebParser
...
FinishAction=[!EnableMeasure MeasureSub][!UpdateMeasure MeasureSub]

[MeasureSub]
Measure=Plugin
Plugin=WebParser
URL=[MeasureYouTube]
StringIndex=1
IfCondition=(MeasureSub<=999)
IfTrueAction=[!SetVariable Subst ""][!SetVariable Subst2 ""][!UpdateMeasure "MeasureSubGrouped"][!UpdateMeter MeterValue][!Redraw]
IfCondition2=((MeasureSub>999)&&(MeasureSub<=999999))
IfTrueAction2=[!SetVariable Subst "(\d{0,3})(\d{3})"][!SetVariable Subst2 "\1 \2"][!UpdateMeasure "MeasureSubGrouped"][!UpdateMeter MeterValue][!Redraw]
IfCondition3=((MeasureSub>999999)&&(MeasureSub<=999999999))
IfTrueAction3=[!SetVariable Subst "(\d{0,3})(\d{3})(\d{3})"][!SetVariable Subst2 "\1 \2 \3"][!UpdateMeasure "MeasureSubGrouped"][!UpdateMeter MeterValue][!Redraw]
IfCondition4=((MeasureSub>999999999)&&(MeasureSub<=999999999999))
IfTrueAction4=[!SetVariable Subst "(\d{0,3})(\d{3})(\d{3})(\d{3})"][!SetVariable Subst2 "\1 \2 \3 \4"][!UpdateMeasure "MeasureSubGrouped"][!UpdateMeter MeterValue][!Redraw]
IfCondition5=((MeasureSub>999999999999)&&(MeasureSub<=999999999999999))
IfTrueAction5=[!SetVariable Subst "(\d{0,3})(\d{3})(\d{3})(\d{3})(\d{3})"][!SetVariable Subst2 "\1 \2 \3 \4 \5"][!UpdateMeasure "MeasureSubGrouped"][!UpdateMeter MeterValue][!Redraw]
IfCondition6=((MeasureSub>999999999999999)&&(MeasureSub<=999999999999999999))
IfTrueAction6=[!SetVariable Subst "(\d{0,3})(\d{3})(\d{3})(\d{3})(\d{3})(\d{3})"][!SetVariable Subst2 "\1 \2 \3 \4 \5 \6"][!UpdateMeasure "MeasureSubGrouped"][!UpdateMeter MeterValue][!Redraw]
Disabled=1

[MeasureSubGrouped]
Measure=String
String=[MeasureSub]
RegExpSubstitute=1
Substitute="#Subst#":"#Subst2#"
DynamicVariables=1

[MeterValue]
Meter=String
MeasureName=MeasureSubGrouped
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
SolidColor=0,0,0,150
FontSize=15
FontFace=Calibri
StringStyle=BOLD
Text=%1 subscribers
AntiAlias=1