It is currently April 24th, 2024, 9:40 am

Help with webparser and JSON

Get help with creating, editing & fixing problems with skins
50l3r
Posts: 24
Joined: August 19th, 2015, 6:11 pm

Re: Help with webparser and JSON

Post by 50l3r »

This is the updated code:

Code: Select all

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

[Metadata]
Name=Discord User Status
Author=50l3r
Information=View discord user avatar and status
Version=1.0

[Variables]
UserID=159985870458322944
ServerID=260710162891800576
StatusOnline=67,181,129,255
Statusidle=250,166,26,255
Statusdnd=240,71,71,255

[MeasureDiscord]
Measure=Plugin
Plugin=WebParser.dll
URL=https://discordapp.com/api/servers/#ServerID#/widget.json
RegExp='(?siU)(?(?=\{.*"id": "#UserID#"\}).*?(\{"username".*"id": "#UserID#"\}))'
UpdateRate=30
DynamicVariables=1

[MeasureUserName]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1
RegExp='(?siU).*"username": "(.*)".*'
StringIndex2=1

[MeasureDiscordStatus]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1
RegExp='(?siU).*"status": "(.*)".*'
StringIndex2=1
DecodeCharacterReference=1
Substitute="\u2713":"✓"
IfMatch=online
IfMatchAction=[!SetOption MeterDiscordStatus ImageTint #StatusOnline#]
IfMatch2=idle
IfMatchAction2=[!SetOption MeterDiscordStatus ImageTint #Statusidle#]
IfMatch3=dnd
IfMatchAction3=[!SetOption MeterDiscordStatus ImageTint #Statusdnd#]
IfMatch4=online|idle|dnd
IfNotMatchAction4=[!SetOption MeterDiscordStatus ImageTint 0,0,0,1]
IfMatchMode=1	

[MeasureAvatarURL]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1
RegExp='(?siU).*"avatar_url": "(.*)".*'
StringIndex2=1
Download=1
OnDownloadErrorAction=[!SetOption AvatarDefault Hidden 0]

[AvatarDefault]
Meter=Image
ImageName="C:\Users\50l3r\Documents\Rainmeter\Skins\StressMeter\@Resources\Discord\1.jpg"
x=0
y=0
w=75
h=75
MaskImageName=#@#images\Masks\Mask
Hidden=1

[Avatar1]
Meter=Image
MeasureName=MeasureAvatarURL
ImageName=%1
x=0
y=0
w=75
h=75
MaskImageName=#@#images\Masks\Mask
Group=Avatar

[MeterDiscordStatus]
Meter=Image
ImageName=#@#images\status\status.PNG
ImageTint=0,0,0,1
x=0
y=0
w=75
h=75
I added a AvatarDefault meter with default avatar and Hidden=1.

I use OnDownloadErrorAction in avatar measure to set avatar default as visible. But it dont work
User avatar
Yincognito
Rainmeter Sage
Posts: 7152
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Help with webparser and JSON

Post by Yincognito »

50l3r wrote: March 11th, 2019, 9:32 amI added a AvatarDefault meter with default avatar and Hidden=1. I use OnDownloadErrorAction in avatar measure to set avatar default as visible. But it dont work.
I think a better approach is to use the already present IfNotMatchAction4 in MeasureDiscordStatus, which will make the default avatar image visible if the discord status is other than online|idle|dnd (ideally, this should be triggered only if the string is empty, but it will work the way it is now nevertheless). The (possible) reasons things didn't work in your attempt were:
- you never updated the meter after making it visible (this is done by appending the [!UpdateMeter AvatarDefault] bang after changing the Hidden option)
- the [AvatarDefault] meter was drawn before [Avatar1], so, in theory, [Avatar1] could "draw over" [AvatarDefault] (a simple positional swap corrected this)
- most importantly, OnDownloadErrorAction was NEVER reached in your scenario, since the avatar image string being empty due to the user not being present in the source string meant that there wasn't any image to download, thus no error being triggered (this is why a better approach was to just simply check if any of the elements you get from the source string are empty - and this is where the fact that you already had some IfMatch options was useful; of course, you can move the AvatarDefault modification code wherever you get elements from the source, not just in [MeasureDiscordStatus])

The updated skin code:

Code: Select all

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

[Metadata]
Name=Discord User Status
Author=50l3r
Information=View discord user avatar and status
Version=1.0

[Variables]
UserID=159985870458322944
ServerID=260710162891800576
StatusOnline=67,181,129,255
Statusidle=250,166,26,255
Statusdnd=240,71,71,255

[MeasureDiscord]
Measure=Plugin
Plugin=WebParser.dll
URL=https://discordapp.com/api/servers/#ServerID#/widget.json
RegExp='(?siU)(?(?=\{.*"id": "#UserID#"\}).*?(\{"username".*"id": "#UserID#"\}))'
UpdateRate=30
DynamicVariables=1

[MeasureUserName]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1
RegExp='(?siU).*"username": "(.*)".*'
StringIndex2=1

[MeasureDiscordStatus]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1
RegExp='(?siU).*"status": "(.*)".*'
StringIndex2=1
DecodeCharacterReference=1
Substitute="\u2713":"✓"
IfMatch=online
IfMatchAction=[!SetOption MeterDiscordStatus ImageTint #StatusOnline#][!SetOption AvatarDefault Hidden 1][!UpdateMeter AvatarDefault]
IfMatch2=idle
IfMatchAction2=[!SetOption MeterDiscordStatus ImageTint #Statusidle#][!SetOption AvatarDefault Hidden 1][!UpdateMeter AvatarDefault]
IfMatch3=dnd
IfMatchAction3=[!SetOption MeterDiscordStatus ImageTint #Statusdnd#][!SetOption AvatarDefault Hidden 1][!UpdateMeter AvatarDefault]
IfMatch4=online|idle|dnd
IfNotMatchAction4=[!SetOption MeterDiscordStatus ImageTint 0,0,0,1][!SetOption AvatarDefault Hidden 0][!UpdateMeter AvatarDefault]
IfMatchMode=1	

[MeasureAvatarURL]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1
RegExp='(?siU).*"avatar_url": "(.*)".*'
StringIndex2=1
Download=1

[Avatar1]
Meter=Image
MeasureName=MeasureAvatarURL
ImageName=%1
x=0
y=0
w=75
h=75
MaskImageName=#@#images\Masks\Mask
Group=Avatar

[AvatarDefault]
Meter=Image
ImageName="F:\Wireless\aaa.jpg"
x=0
y=0
w=75
h=75
MaskImageName=#@#images\Masks\Mask
Hidden=1

[MeterDiscordStatus]
Meter=Image
ImageName=#@#images\status\status.PNG
ImageTint=0,0,0,1
x=0
y=0
w=75
h=75
Make sure you restore the path to your default image in AvatarDefault meter. I had to use another quickly self-made image as default as you didn't upload your 1.jpg.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
50l3r
Posts: 24
Joined: August 19th, 2015, 6:11 pm

Re: Help with webparser and JSON

Post by 50l3r »

Yincognito wrote: March 11th, 2019, 1:45 pm I think a better approach is to use the already present IfNotMatchAction4 in MeasureDiscordStatus, which will make the default avatar image visible if the discord status is other than online|idle|dnd (ideally, this should be triggered only if the string is empty, but it will work the way it is now nevertheless). The (possible) reasons things didn't work in your attempt were:
- you never updated the meter after making it visible (this is done by appending the [!UpdateMeter AvatarDefault] bang after changing the Hidden option)
- the [AvatarDefault] meter was drawn before [Avatar1], so, in theory, [Avatar1] could "draw over" [AvatarDefault] (a simple positional swap corrected this)
- most importantly, OnDownloadErrorAction was NEVER reached in your scenario, since the avatar image string being empty due to the user not being present in the source string meant that there wasn't any image to download, thus no error being triggered (this is why a better approach was to just simply check if any of the elements you get from the source string are empty - and this is where the fact that you already had some IfMatch options was useful; of course, you can move the AvatarDefault modification code wherever you get elements from the source, not just in [MeasureDiscordStatus])

The updated skin code:

Code: Select all

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

[Metadata]
Name=Discord User Status
Author=50l3r
Information=View discord user avatar and status
Version=1.0

[Variables]
UserID=159985870458322944
ServerID=260710162891800576
StatusOnline=67,181,129,255
Statusidle=250,166,26,255
Statusdnd=240,71,71,255

[MeasureDiscord]
Measure=Plugin
Plugin=WebParser.dll
URL=https://discordapp.com/api/servers/#ServerID#/widget.json
RegExp='(?siU)(?(?=\{.*"id": "#UserID#"\}).*?(\{"username".*"id": "#UserID#"\}))'
UpdateRate=30
DynamicVariables=1

[MeasureUserName]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1
RegExp='(?siU).*"username": "(.*)".*'
StringIndex2=1

[MeasureDiscordStatus]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1
RegExp='(?siU).*"status": "(.*)".*'
StringIndex2=1
DecodeCharacterReference=1
Substitute="\u2713":"✓"
IfMatch=online
IfMatchAction=[!SetOption MeterDiscordStatus ImageTint #StatusOnline#][!SetOption AvatarDefault Hidden 1][!UpdateMeter AvatarDefault]
IfMatch2=idle
IfMatchAction2=[!SetOption MeterDiscordStatus ImageTint #Statusidle#][!SetOption AvatarDefault Hidden 1][!UpdateMeter AvatarDefault]
IfMatch3=dnd
IfMatchAction3=[!SetOption MeterDiscordStatus ImageTint #Statusdnd#][!SetOption AvatarDefault Hidden 1][!UpdateMeter AvatarDefault]
IfMatch4=online|idle|dnd
IfNotMatchAction4=[!SetOption MeterDiscordStatus ImageTint 0,0,0,1][!SetOption AvatarDefault Hidden 0][!UpdateMeter AvatarDefault]
IfMatchMode=1	

[MeasureAvatarURL]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1
RegExp='(?siU).*"avatar_url": "(.*)".*'
StringIndex2=1
Download=1

[Avatar1]
Meter=Image
MeasureName=MeasureAvatarURL
ImageName=%1
x=0
y=0
w=75
h=75
MaskImageName=#@#images\Masks\Mask
Group=Avatar

[AvatarDefault]
Meter=Image
ImageName="F:\Wireless\aaa.jpg"
x=0
y=0
w=75
h=75
MaskImageName=#@#images\Masks\Mask
Hidden=1

[MeterDiscordStatus]
Meter=Image
ImageName=#@#images\status\status.PNG
ImageTint=0,0,0,1
x=0
y=0
w=75
h=75
Make sure you restore the path to your default image in AvatarDefault meter. I had to use another quickly self-made image as default as you didn't upload your 1.jpg.
Great! It works. Thats the code:

Code: Select all

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

[Metadata]
Name=Discord User Status
Author=50l3r
Information=View discord user avatar and status
Version=1.0

[Variables]
@include=#ROOTCONFIGPATH#Variables.inc
UserID=#DiscordUser2#
ServerID=260710162891800576
StatusOnline=67,181,129,255
Statusidle=250,166,26,255
Statusdnd=240,71,71,255

[MeasureDiscord]
Measure=Plugin
Plugin=WebParser.dll
URL=https://discordapp.com/api/servers/#ServerID#/widget.json
RegExp='(?siU)(?(?=\{.*"id": "#UserID#"\}).*?(\{"username".*"id": "#UserID#"\}))'
UpdateRate=30
DynamicVariables=1

[MeasureUserName]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1
RegExp='(?siU).*"username": "(.*)".*'
StringIndex2=1

[MeasureDiscordStatus]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1
RegExp='(?siU).*"status": "(.*)".*'
StringIndex2=1
DecodeCharacterReference=1
Substitute="\u2713":"✓"
IfMatch=online
IfMatchAction=[!SetOption MeterDiscordStatus ImageTint #StatusOnline#]
IfMatch2=idle
IfMatchAction2=[!SetOption MeterDiscordStatus ImageTint #Statusidle#]
IfMatch3=dnd
IfMatchAction3=[!SetOption MeterDiscordStatus ImageTint #Statusdnd#]
IfMatch4=online|idle|dnd
IfNotMatchAction4=[!SetOption MeterDiscordStatus ImageTint 140,140,140,255][!SetOption AvatarDefault Hidden 0][!SetOption AvatarDefault GreyScale 1]
IfMatchMode=1

[MeasureAvatarURL]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1
RegExp='(?siU).*"avatar_url": "(.*)".*'
StringIndex2=1
Download=1
OnDownloadErrorAction=[!SetOption AvatarDefault Hidden 0]

[MeasureImageDefault]
Measure=Plugin
Plugin=WebParser
URL=#DiscordUserAvatar2#
Download=1

[AvatarDefault]
Meter=Image
MeasureName=MeasureImageDefault
x=0
y=0
w=75
h=75
MaskImageName=#ROOTCONFIGPATH#@Resources\Discord\Masks\Mask.png
Hidden=1
LeftMouseDoubleClickAction=!Execute ["#DiscordPath#"]

[Avatar1]
Meter=Image
MeasureName=MeasureAvatarURL
ImageName=%1
x=0
y=0
w=75
h=75
MaskImageName=#ROOTCONFIGPATH#@Resources\Discord\Masks\Mask.png
Group=Avatar
Antialiasing=1
LeftMouseDoubleClickAction=!Execute ["#DiscordPath#"]

[MeterDiscordStatus]
Meter=Image
ImageName=#ROOTCONFIGPATH#@Resources\Discord\status\status.png
ImageTint=0,0,0,1
x=0
y=0
w=75
h=75
The result:

Image

I'l add this skins to my pack :D : https://www.deviantart.com/500l3r/art/StressMeter-2-0-773922723
User avatar
Yincognito
Rainmeter Sage
Posts: 7152
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Help with webparser and JSON

Post by Yincognito »

Nice! Enjoy the benefits and good luck to gaming. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth