It is currently November 14th, 2019, 7:35 am

Help with webparser and JSON

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

Help with webparser and JSON

50l3r » March 6th, 2019, 5:09 pm

Hi guys,

I need to extract a specific user based on id in this json:

https://discordapp.com/api/servers/260710162891800576/widget.json

Actually, i have this webparser who give the first user:

Code: Select all

RegExp=(?siU)"user(.*) "id": "(.*)"}
And give me:

Code: Select all

"username": "50l3r", "status": "online", "avatar_url": "https://cdn.discordapp.com/avatars/154958592523501568/3931543ca12c107617d6d999ab2ae57f.jpg", "avatar": "3931543ca12c107617d6d999ab2ae57f", "discriminator": "1944", "id": "154958592523501568"}
But i need to extract a specific user, based on id like "154958592523501568"

This is my vars:

Image

Anyone can help me? Thanks
User avatar
FreeRaider
Posts: 788
Joined: November 20th, 2012, 11:58 pm

Re: Help with webparser and JSON

FreeRaider » March 6th, 2019, 5:39 pm

Do you want something like this one?

Code: Select all

(?siU)(?(?!"id": "154958592523501568").*username":.*"(.*)",.*id.*)
User avatar
balala
Rainmeter Sage
Posts: 9039
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with webparser and JSON

balala » March 6th, 2019, 6:18 pm

50l3r wrote:
March 6th, 2019, 5:09 pm
I need to extract a specific user based on id in this json:
FreeRaider's solution is quite good, however what I didn't understand is what you need from the specific user: just the name or something more too? If the name is enough, use FreeRaider's RegExp, otherwise, let us know.
50l3r
Posts: 24
Joined: August 19th, 2015, 6:11 pm

Re: Help with webparser and JSON

50l3r » March 6th, 2019, 6:22 pm

I need all user data from specific user:

Code: Select all

"username": "50l3r", "status": "online", "avatar_url": "https://cdn.discordapp.com/avatars/154958592523501568/3931543ca12c107617d6d999ab2ae57f.jpg", "avatar": "3931543ca12c107617d6d999ab2ae57f", "discriminator": "1944", "id": "154958592523501568"}
User avatar
balala
Rainmeter Sage
Posts: 9039
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with webparser and JSON

balala » March 6th, 2019, 6:57 pm

50l3r wrote:
March 6th, 2019, 6:22 pm
I need all user data from specific user:

Code: Select all

"username": "50l3r", "status": "online", "avatar_url": "https://cdn.discordapp.com/avatars/154958592523501568/3931543ca12c107617d6d999ab2ae57f.jpg", "avatar": "3931543ca12c107617d6d999ab2ae57f", "discriminator": "1944", "id": "154958592523501568"}
Then try out the following measures:

Code: Select all

[MeasureRainmeter]
Measure=WebParser
UpdateRate=900
Url=...
RegExp=(?siU)\{"username": "(.*)", "status": "(.*)", "avatar_url": "(.*)", "avatar": "(.*)", "discriminator": "(.*)", "id": "154958592523501568"}

[MeasureUserName]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=1

[MeasureStatus]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=2

[MeasureAvatar]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=3

[MeasureDiscriminator]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=4
[MeasureUserName], [MeasureStatus], [MeasureAvatar] and [MeasureDiscriminator] give you the needed information accordingly. Don't forget to add the URL into the [MeasureRainmeter] measure.
50l3r
Posts: 24
Joined: August 19th, 2015, 6:11 pm

Re: Help with webparser and JSON

50l3r » March 6th, 2019, 7:46 pm

balala wrote:
March 6th, 2019, 6:57 pm
Then try out the following measures:

Code: Select all

[MeasureRainmeter]
Measure=WebParser
UpdateRate=900
Url=...
RegExp=(?siU)\{"username": "(.*)", "status": "(.*)", "avatar_url": "(.*)", "avatar": "(.*)", "discriminator": "(.*)", "id": "154958592523501568"}

[MeasureUserName]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=1

[MeasureStatus]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=2

[MeasureAvatar]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=3

[MeasureDiscriminator]
Measure=WebParser
Url=[MeasureRainmeter]
StringIndex=4
[MeasureUserName], [MeasureStatus], [MeasureAvatar] and [MeasureDiscriminator] give you the needed information accordingly. Don't forget to add the URL into the [MeasureRainmeter] measure.
I change the id but i catch the first, not the exact user. I only need one user:

Image

Thats the skin:

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=308630807625465857
	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)\{"username": "(.*)", "status": "(.*)", "avatar_url": "(.*)", "avatar": "(.*)", "discriminator": "(.*)", "id": "#UserID#"}
	UpdateRate=30

[MeasureDiscordAvatar]
	Measure=Plugin
	Plugin=WebParser.dll
	URL=[MeasureDiscord]
	StringIndex=3
	Download=1	

[MeasureDiscordStatus1]
	Measure=WebParser
	URL=[MeasureDiscord]
	StringIndex=2
	DecodeCharacterReference=1
	Substitute="\u2713":"✓"
	IfMatch=online
	IfMatchAction=[!SetOption MeterDiscordStatus1 ImageTint #StatusOnline#]
	IfMatch2=idle
	IfMatchAction2=[!SetOption MeterDiscordStatus1 ImageTint #Statusidle#]
	IfMatch3=dnd
	IfMatchAction3=[!SetOption MeterDiscordStatus1 ImageTint #Statusdnd#]
	IfMatch4=online|idle|dnd
	IfNotMatchAction4=[!SetOption MeterDiscordStatus1 ImageTint 0,0,0,1]
	IfMatchMode=1	

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

[MeterDiscordStatus1]
	Meter=Image
	ImageName=#@#images\status\status.PNG
	ImageTint=0,0,0,1
	x=0
	y=0
	w=75
	h=75

[MeasureDiscriminator]
Measure=WebParser
Url=[MeasureDiscord]
StringIndex=4
User avatar
balala
Rainmeter Sage
Posts: 9039
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with webparser and JSON

balala » March 6th, 2019, 8:35 pm

50l3r wrote:
March 6th, 2019, 7:46 pm
I change the id but i catch the first, not the exact user. I only need one user:
I think the data structure available in the online accessible .json file is a little bit different then one posted previously by you. Accordingly I had to rewrite (again) the RegExp. Now there are much more information available. Here are the rewritten WebParser measures:

Code: Select all

[MeasureDiscord]
Measure=Plugin
Plugin=WebParser.dll
URL=https://discordapp.com/api/servers/#ServerID#/widget.json
RegExp=(?siU)\{"username": "(.*)", "status": "(.*)", "mute": (.*), "suppress": (.*), "deaf": (.*), "channel_id": "(.*)", "avatar_url": "(.*)", "avatar": "(.*)", "self_deaf": (.*), "discriminator": "(.*)", "self_mute": (.*), "id": "#UserID#"}
;RegExp=(?siU)\{"username": "(.*)", "status": "(.*)", "avatar_url": "(.*)", "avatar": "(.*)", "discriminator": "(.*)", "id": "#UserID#"}
UpdateRate=30
LogSubstringErrors=0
FinishAction=[!DisableMeasure MeasureWidget][!SetOption MeterDiscordUser1 Text "%1"][!SetOption MeterDiscordUser2 Text "%1"][!SetOption MeterDiscordUser3 Text "%1"][!ShowMeterGroup Avatar]
OnRegExpErrorAction=[!EnableMeasure MeasureWidget][!HideMeterGroup Avatar]
OnConnectErrorAction=[!SetOption MeterDiscordUser1 Text "Error-"][!SetOption MeterDiscordUser2 Text "No Internet"][!SetOption MeterDiscordUser3 Text "Access"]
;Download=1

[MeasureUserName]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1

[MeasureStatus]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=2

[MeasureMute]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=3

[MeasureSupress]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=4

[MeasureDeaf]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=5

[MeasureChannelID]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=6

[MeasureAvatarURL]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=7

[MeasureAvatar]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=8

[MeasureSealfDeaf]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=9

[MeasureDiscriminator]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=10

[MeasureSelfMute]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=11
Note that I also have rewritten the measures to be WebParser measures, instead of being Plugin measures. A while ago (and note that for now it was a long time ago), WebParser became measure and you should have to use them accordingly.
One more: for the appropriate user (50l3r), the UserId is not 177117512763179008, but UserID=154958592523501568. Am I wrong about this?
50l3r
Posts: 24
Joined: August 19th, 2015, 6:11 pm

Re: Help with webparser and JSON

50l3r » March 6th, 2019, 10:38 pm

balala wrote:
March 6th, 2019, 8:35 pm
I think the data structure available in the online accessible .json file is a little bit different then one posted previously by you. Accordingly I had to rewrite (again) the RegExp. Now there are much more information available. Here are the rewritten WebParser measures:

Code: Select all

[MeasureDiscord]
Measure=Plugin
Plugin=WebParser.dll
URL=https://discordapp.com/api/servers/#ServerID#/widget.json
RegExp=(?siU)\{"username": "(.*)", "status": "(.*)", "mute": (.*), "suppress": (.*), "deaf": (.*), "channel_id": "(.*)", "avatar_url": "(.*)", "avatar": "(.*)", "self_deaf": (.*), "discriminator": "(.*)", "self_mute": (.*), "id": "#UserID#"}
;RegExp=(?siU)\{"username": "(.*)", "status": "(.*)", "avatar_url": "(.*)", "avatar": "(.*)", "discriminator": "(.*)", "id": "#UserID#"}
UpdateRate=30
LogSubstringErrors=0
FinishAction=[!DisableMeasure MeasureWidget][!SetOption MeterDiscordUser1 Text "%1"][!SetOption MeterDiscordUser2 Text "%1"][!SetOption MeterDiscordUser3 Text "%1"][!ShowMeterGroup Avatar]
OnRegExpErrorAction=[!EnableMeasure MeasureWidget][!HideMeterGroup Avatar]
OnConnectErrorAction=[!SetOption MeterDiscordUser1 Text "Error-"][!SetOption MeterDiscordUser2 Text "No Internet"][!SetOption MeterDiscordUser3 Text "Access"]
;Download=1

[MeasureUserName]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1

[MeasureStatus]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=2

[MeasureMute]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=3

[MeasureSupress]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=4

[MeasureDeaf]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=5

[MeasureChannelID]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=6

[MeasureAvatarURL]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=7

[MeasureAvatar]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=8

[MeasureSealfDeaf]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=9

[MeasureDiscriminator]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=10

[MeasureSelfMute]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=11
Note that I also have rewritten the measures to be WebParser measures, instead of being Plugin measures. A while ago (and note that for now it was a long time ago), WebParser became measure and you should have to use them accordingly.
One more: for the appropriate user (50l3r), the UserId is not 177117512763179008, but UserID=154958592523501568. Am I wrong about this?
I update the code, but any thing its not work

There is a example of json: https://pastebin.com/eB3sx6sp

For example, i need to get the data of username "MEE6" wich id: 159985870458322944

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]
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)\{"username": "(.*)", "status": "(.*)", "mute": (.*), "suppress": (.*), "deaf": (.*), "channel_id": "(.*)", "avatar_url": "(.*)", "avatar": "(.*)", "self_deaf": (.*), "discriminator": "(.*)", "self_mute": (.*), "id": "#UserID#"}
UpdateRate=30

[MeasureUserName]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=1

[MeasureDiscordStatus]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=2
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	

[MeasureMute]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=3

[MeasureSupress]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=4

[MeasureDeaf]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=5

[MeasureChannelID]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=6

[MeasureAvatarURL]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=7

[MeasureAvatar]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=8

[MeasureSealfDeaf]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=9

[MeasureDiscriminator]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=10

[MeasureSelfMute]
Measure=WebParser
URL=[MeasureDiscord]
StringIndex=11

[MeasureDiscordAvatar]
Measure=Plugin
Plugin=WebParser.dll
URL=[MeasureDiscord]
StringIndex=7
Download=1	

[Avatar1]
Meter=Image
MeasureName=MeasureDiscordAvatar
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

[MeasureDiscriminator]
Measure=WebParser
Url=[MeasureDiscord]
StringIndex=4
But i recieve wrong data:

Image

The measurediscord value:

Code: Select all

{"username": "50l3r", "status": "online", "game": {"name": "Spotify"}, "avatar_url": "https://cdn.discordapp.com/avatars/154958592523501568/3931543ca12c107617d6d999ab2ae57f.jpg", "avatar": "3931543ca12c107617d6d999ab2ae57f", "discriminator": "1944", "id": "154958592523501568"}, {"username": "_Xaser", "status": "idle", "avatar_url": "https://cdn.discordapp.com/avatars/209305741562085376/a405eac3f3723b7ec328c1bf3393fbe4.jpg", "avatar": "a405eac3f3723b7ec328c1bf3393fbe4", "discriminator": "3327", "id": "209305741562085376"}, {"username": "Alecaco", "status": "online", "avatar_url": "https://cdn.discordapp.com/avatars/284798610741133313/5435c87b08c3f375163a67ea1229f9a4.jpg", "avatar": "5435c87b08c3f375163a67ea1229f9a4", "discriminator": "9279", "id": "284798610741133313"}, {"username": "Anchovy", "status": "online", "game": {"name": "Warframe"}, "avatar_url": "https://cdn.discordapp.com/avatars/177117512763179008/25ad7b84318368aa9abadaca34cb3bc7.jpg", "avatar": "25ad7b84318368aa9abadaca34cb3bc7", "discriminator": "8047", "id": "177117512763179008"}, {"username": "bailonidas", "status": "online", "avatar_url": "https://cdn.discordapp.com/avatars/172466452442382336/cf4d3f669c4de87c5f0cd03e7c022032.jpg", "avatar": "cf4d3f669c4de87c5f0cd03e7c022032", "discriminator": "0420", "id": "172466452442382336"}, {"username": "bololo", "status": "online", "avatar_url": "https://cdn.discordapp.com/avatars/174072737810219009/ff06313bc7da53426f00aa4e3bd9fe3b.jpg", "avatar": "ff06313bc7da53426f00aa4e3bd9fe3b", "discriminator": "4553", "id": "174072737810219009"}, {"username": "cabeso", "status": "online", "avatar_url": "https://cdn.discordapp.com/avatars/266253963542790145/09ef927c08817434a2270b466ede6177.jpg", "avatar": "09ef927c08817434a2270b466ede6177", "discriminator": "0315", "id": "266253963542790145"}, {"username": "Crafdivad", "status": "online", "avatar_url": "https://cdn.discordapp.com/avatars/180993412164616192/763ae866867b39155aeff670aeef6646.jpg", "avatar": "763ae866867b39155aeff670aeef6646", "discriminator": "9772", "id": "180993412164616192"}, {"username": "Esfvc", "status": "online", "avatar_url": "https://cdn.discordapp.com/avatars/448200129804238869/36b653c9c0b0fc1c73fb0101a67ee2b9.jpg", "avatar": "36b653c9c0b0fc1c73fb0101a67ee2b9", "discriminator": "6335", "id": "448200129804238869"}, {"username": "eXeToR", "status": "idle", "avatar_url": "https://cdn.discordapp.com/avatars/150689902839726081/220d8a078cd78e4cd933f8574fba7463.jpg", "avatar": "220d8a078cd78e4cd933f8574fba7463", "discriminator": "9860", "id": "150689902839726081"}, {"username": "FeR!__[4]", "status": "idle", "mute": false, "suppress": true, "deaf": false, "channel_id": "283698219194777601", "avatar_url": "https://cdn.discordapp.com/avatars/154959066580385793/f865b8a22c1f08b6a48b21c2886de8b9.jpg", "avatar": "f865b8a22c1f08b6a48b21c2886de8b9", "self_deaf": true, "discriminator": "9873", "self_mute": true, "id": "154959066580385793"}, {"username": "Fri", "status": "online", "avatar_url": "https://cdn.discordapp.com/embed/avatars/0.png", "avatar": null, "discriminator": "7485", "id": "125977819154087937"}, {"username": "Hyndu", "status": "online", "game": {"name": "Spotify"}, "avatar_url": "https://cdn.discordapp.com/avatars/158897541004525568/a68fa43cdc584fdba060254244176d1a.jpg", "avatar": "a68fa43cdc584fdba060254244176d1a", "discriminator": "6470", "id": "158897541004525568"}, {"username": "Khar_xP", "status": "online", "game": {"name": "Fortnite"}, "avatar_url": "https://cdn.discordapp.com/avatars/300685560773738497/d96191ca1bfe4dc9df6aebffb49fc4c0.jpg", "avatar": "d96191ca1bfe4dc9df6aebffb49fc4c0", "discriminator": "4231", "id": "300685560773738497"}, {"username": "Kr\u00f8gar", "status": "online", "game": {"name": "World of Warcraft"}, "avatar_url": "https://cdn.discordapp.com/avatars/176804592623943681/ac84e944a2218f8db97f88c093b3de56.jpg", "avatar": "ac84e944a2218f8db97f88c093b3de56", "discriminator": "5753", "id": "176804592623943681"}, {"username": "MEE6", "status": "online", "bot": true, "avatar_url": "https://cdn.discordapp.com/avatars/159985870458322944/b50adff099924dd5e6b72d13f77eb9d7.jpg", "avatar": "b50adff099924dd5e6b72d13f77eb9d7", "discriminator": "4876", "id": "159985870458322944"}
Much thanks for your time
User avatar
balala
Rainmeter Sage
Posts: 9039
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with webparser and JSON

balala » March 7th, 2019, 1:41 pm

The last posted code doesn't work at all with the posted json example. I get a RegExp matching error (-1) message in log.
50l3r
Posts: 24
Joined: August 19th, 2015, 6:11 pm

Re: Help with webparser and JSON

50l3r » March 7th, 2019, 1:45 pm

balala wrote:
March 7th, 2019, 1:41 pm
The last posted code doesn't work at all with the posted json example. I get a RegExp matching error (-1) message in log.
I think it's because sometimes user ids do not exist. That JSON only returns the connected users apparently :(