It is currently April 12th, 2021, 3:51 am

Donating plugins: JsonParser and RSS

Share and get help with Plugins and Addons
spook
Posts: 7
Joined: September 9th, 2020, 2:07 pm

Donating plugins: JsonParser and RSS

Post by spook »

Hi!

I wrote two custom plugins for my Rainmeter skin, Win10Skin:

http://spook.ayz.pl/public/images/rainmeter/Win10Skin.png

I needed to parse JSON for weather and process RSS feed. Although it technically can be done with WebParser, using regular expressions in this case is cumbersome and ineffective, so I wrote dedicated plugins for that. Example of usage of JsonParser:

Code: Select all

[MeasureWeather]
Measure=WebParser
UpdateRate=5
URL=https://api.openweathermap.org/data/2.5/onecall?lat=51.10&lon=17.03&units=metric&appid=#ApiKey#
RegExp=(?siU)^(.*)$
OnUpdateAction=[!CommandMeasure MeasureWeatherUpdater "Execute 1"]

[MeasureWeatherUpdater]
Measure=Plugin
Plugin=ActionTimer
ActionList1=Wait 5000 | SetSource | UpdateTemperature | UpdateHumidity | UpdatePressure | UpdateIcon | RedrawAll
SetSource=[!SetOption "MeasureJson" "Source" [MeasureWeatherJsonCapture]]
UpdateTemperature=[!SetOption "MeterTemperature" "Text" [MeasureJson:Query("current.temp")]][!UpdateMeter "MeterTemperature"]
UpdateHumidity=[!SetOption "MeterHumidity" "Text" [MeasureJson:Query("current.humidity")]][!UpdateMeter "MeterHumidity"]
UpdatePressure=[!SetOption "MeterPressure" "Text" [MeasureJson:Query("current.pressure")]][!UpdateMeter "MeterPressure"]
UpdateIcon=[!Log [MeasureJson:Query("current.weather(0).icon")]][!SetOption "MeterIcon" "ImageName" [MeasureJson:Query("current.weather(0).icon")]][!UpdateMeter "MeterIcon"]
RedrawAll=[!Redraw]

[MeasureWeatherJsonCapture]
Measure=WebParser
URL=[MeasureWeather]
StringIndex=1

[MeasureJson]
Measure=Plugin
Plugin=PluginJsonParser
Precision=1
Source=
Query=
Debug=0
Thanks to the Query custom action you can parse JSON only once (in my case source for that is WebParser, which downloads page), and then simply query for its contents with a "dot notation".

The RSS plugin, on the other hand, does all the work: downloads multiple feeds, parses them and supports pagination and switching from one feed to another. Example:

Code: Select all

[MeasureNews]
Measure=Plugin
Plugin=PluginRss
PageSize=5
Debug=1
Url=https://www.nintendoswitch.pl/feed
Url2=https://portaltechnologiczny.pl/category/technews/feed/
Url3=https://sdtimes.com/feed/
Url4=https://www.tomshardware.com/feeds/all
Url5=https://botland.com.pl/blog/feed/
OnUpdateAction=[!CommandMeasure MeasureNewsUpdater "Execute 1"]

[MeasureNewsUpdater]
Measure=Plugin
Plugin=ActionTimer
ActionList1=UpdateChannelTitle | UpdateEntry1Title | UpdateEntry2Title | UpdateEntry3Title | UpdateEntry4Title | UpdateEntry5Title | RedrawAll
UpdateChannelTitle=[!SetOption "MeterChannelTitle" "Text" [MeasureNews:GetCurrentChannelTitle()]][!UpdateMeter "MeterChannelTitle"]
UpdateEntry1Title=[!SetOption "MeterEntry1Title" "Text" [MeasureNews:GetEntryTitle(0)]][!UpdateMeter "MeterEntry1Title"]
UpdateEntry2Title=[!SetOption "MeterEntry2Title" "Text" [MeasureNews:GetEntryTitle(1)]][!UpdateMeter "MeterEntry2Title"]
UpdateEntry3Title=[!SetOption "MeterEntry3Title" "Text" [MeasureNews:GetEntryTitle(2)]][!UpdateMeter "MeterEntry3Title"]
UpdateEntry4Title=[!SetOption "MeterEntry4Title" "Text" [MeasureNews:GetEntryTitle(3)]][!UpdateMeter "MeterEntry4Title"]
UpdateEntry5Title=[!SetOption "MeterEntry5Title" "Text" [MeasureNews:GetEntryTitle(4)]][!UpdateMeter "MeterEntry5Title"]
RedrawAll=[!Redraw]

[MeterPreviousChannel]
LeftMouseUpAction=[!CommandMeasure "MeasureNews" "PreviousChannel"][!CommandMeasure "MeasureNewsUpdater" "Execute 1"]

[MeterNextChannel]
LeftMouseUpAction=[!CommandMeasure "MeasureNews" "NextChannel"][!CommandMeasure "MeasureNewsUpdater" "Execute 1"]

[MeterChannelTitle]
Meter=String
MeterStyle=StyleSecondaryText
StringAlign=Center
X=(#DefaultBoxWidth# / 2)
Y=#TopPadding#
W=(#DefaultBoxWidth# - 4 * #LeftPadding# - 2 * #ShapeWidth#)
ClipString=1

[MeterEntry1Title]
Meter=String
MeterStyle=StyleSmallText
X=#LeftPadding#
Y=5R
W=(#DefaultBoxWidth# - 2 * #LeftPadding#)
ClipString=1

; (...)

[MeterPreviousPage]
LeftMouseUpAction=[!CommandMeasure "MeasureNews" "PreviousPage"][!CommandMeasure "MeasureNewsUpdater" "Execute 1"]

[MeterNextPage]
LeftMouseUpAction=[!CommandMeasure "MeasureNews" "NextPage"][!CommandMeasure "MeasureNewsUpdater" "Execute 1"]
It uses custom actions to retrieve paginated entries and channel name and bang commands to switch channels and pages.

Plugin sources are on my Gitlab page: https://gitlab.com/spook/RainmeterPlugins
The skin is also on my Gitlab page: https://gitlab.com/spook/Win10RainmeterSkin

If you are interested in using those plugins, give me a shout and I'll publish binaries on my website too.

Have fun!

Best regards -- Spook.