It is currently April 23rd, 2024, 4:57 pm

counting your Facebook notifications

Tips and Tricks from the Rainmeter Community
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

counting your Facebook notifications

Post by moshi »

i use the Facebook notifications feed. https://www.facebook.com/help/?faq=212445198787494

i thought it would be nice to know the number of notifications, just like <fullcount>(.*)</fullcount> in the GMail inbox feed. as there no such info provided, i thought i'd just count the number of items in the feed. this means i fetch the whole feed and then use a few substitions:

the first four substitions eradicate linebreaks, tabs and other whitespace, the next one eradicates everything before the items start. then everything between <item></item> tags gets removed and also everything after the items end.

what is left is a chain of <item></item><item></item><item></item><item></item>...<item></item>
so let's replace <item> with 1 and </item> with +. to avoid a syntax error, let's replace the the last + with +0.
just in case there are no items in the feed, nothing (^$) gets replaced with 0.

what is left is a chain of 1+1+1+...+1+0. use that as formula in a calc measure. done.

Code: Select all

[MeasureFacebookCountBase]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=#FacebookNotificationFeed#
RegExp="(?siU)^(.*)$"
StringIndex=1
RegExpSubstitute=1
Substitute="\r":"","\n":"","\t":"","\s":"","^(.*?)</webMaster>":"","<item>(.*?)</item>":"<item></item>","^(.*)</channel>(.*?)$":"\1","<item>":"1","</item>":"+","^(.+)$":"\10","^$":"0"
Disabled=1
FinishAction=[!SetOption MeasureFacebookCountAll Formula "[MeasureFacebookCountBase]" "#CURRENTCONFIG#"][!UpdateMeasure MeasureFacebookCountAll][!DisableMeasure MeasureFacebookCountBase]

[MeasureFacebookCountAll]
Measure=Calc
Formula=(0)
DynamicVariables=1

warning: this is heavy on cpu use, depending on the length of the feed. that's why i have it disabled. i enable/update it with a FinishAction when the regular Facebook feed reader measure is done. it gets disabled again when it did it's job.



so, i hope that gives you ideas on counting items in a feed. with a few modifications and the new dynamic webparser plugin, you can use variables either in the RegExp or in the substitutions to eliminate larger parts of the feed and only count new items for example. or items for today only. etc.
User avatar
thatsIch
Posts: 446
Joined: August 7th, 2012, 9:18 pm

Re: counting your Facebook notifications

Post by thatsIch »

Thats an interesting way to handle it, but wouldnt it be easier to replace <item>(.*)</item> directly with 1 +? Or is there a particular reason you have to do it this way?
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: counting your Facebook notifications

Post by moshi »

yes, you could. there are a couple of ways to make the substitution shorter. the point of a tips & tricks post is to communicate things step-by-step though. at least that's my opinion, i am aware that most people would prefer stuff to cut&paste.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: counting your Facebook notifications

Post by smurfier »

FinishAction=[!SetOption MeasureFacebookCountAll Formula "[MeasureFacebookCountBase]" "#CURRENTCONFIG#"][!UpdateMeasure MeasureFacebookCountAll][!DisableMeasure MeasureFacebookCountBase]

With this code you probably don't need DynamicVariables=1 on the MeasureFacebookCountAll, or for that matter on MeasureFacebookCountBase. Section Variables are always dynamically replaced in bangs.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: counting your Facebook notifications

Post by moshi »

true, not really needed.
is there a way to escape those brackets [] ? might be useful at some point (thinking of !WriteKeyValue and not !SetOption).
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: counting your Facebook notifications

Post by smurfier »

I believe it's the same as regular variables: [*Measure*]
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: counting your Facebook notifications

Post by moshi »

yep, that works. thanks.