I'm trying to create a basic skin and get a bit lost with the WebParser. Reading the howto's online, I can't figure out what goes wrong. An example (simple coin value skin):
[BitcoinValueEuro]
Measure=Plugin
Plugin=WebParser
URL=https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=eur
RegExp=(?siU)price_eur": "(.......)
returns the amount of positions same to the amount of dots
RegExp=(?siU)price_eur": "(.*)
Does not work! deleting (?siU) does work and returns the full value
so why doesn't (.*) work when I user (?siU) in the string? Should I just not use (?siU)?
Strangly when using price_usd:
RegExp=(?siU)price_eur": "(.*)".*percent_change_1h": "(.*)".*percent_change_24h": "(.*)".*percent_change_7d": "(.*)"
it returns all values, chaning it to price_eur fails completely...
Regards
It is currently April 25th, 2024, 11:26 am
getting lost in the basics of the WebParser
-
- Posts: 3
- Joined: September 26th, 2017, 5:21 pm
-
- Posts: 3
- Joined: September 26th, 2017, 5:21 pm
Re: getting lost in the basics of the WebParser
I fixed it but not sure if it is the correct way. At least I get my values now:
Code: Select all
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
[BitcoinValueEuro]
Measure=Plugin
Plugin=WebParser
URL=https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=eur
RegExp=(?siU)price_eur": "(.*)"
[Bitcoin1hour]
Measure=Plugin
Plugin=WebParser
URL=https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=eur
RegExp=(?siU)percent_change_1h": ".*"
[Bitcoin24hour]
Measure=Plugin
Plugin=WebParser
URL=https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=eur
RegExp=(?siU)percent_change_24h": ".*"
[Bitcoin7days]
Measure=Plugin
Plugin=WebParser
URL=https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=eur
RegExp=(?siU)percent_change_7d": ".*"
-
- Rainmeter Sage
- Posts: 16168
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: getting lost in the basics of the WebParser
No, it's not. The WebParser measures usually should use a parent - child structure, which means that you have to have a parent measure (which has the Url=https://... option) and one or more child measures, which all use as Url the name of the parent measure (Url=[Bitcoin] - or how have you named the parent measure).EvilUnicorn wrote:I fixed it but not sure if it is the correct way.
On the other hand, the provided URL (https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=eur) is used to download a .json file. In such cases the file, first must be downloaded by a measure, then you have to use other measures to get its content.
The following code uses this approach: first the [MeasureBitcoin] measure downloads the file (due to its Download=1 option). At this point all other WebParser measures are disabled. When the download is finished, the FinishAction option of this measure enables and updates the [Bitcoin] measure, which is the parent measure. This measure will parse the data. When it finishes, will enable the child measures (I included those measures into a group, named Bitcoin), which will return the needed data.
I hope you'll get this code working. Please let me know if you did.
The code:
Code: Select all
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
[MeasureBitcoin]
Measure=Plugin
Plugin=WebParser
Url=https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=eur
Download=1
FinishAction=[!EnableMeasure "Bitcoin"][!CommandMeasure "Bitcoin" "Update"]
UpdateRate=1800
[Bitcoin]
Measure=Plugin
Plugin=WebParser
URL=file://[&MeasureBitcoin]
RegExp=(?siU)"percent_change_1h": "(.*)",.*"percent_change_24h": "(.*)",.*"percent_change_7d": "(.*)",.*"last_updated": ".*",.*"price_eur": "(.*)"
FinishAction=[!EnableMeasureGroup "Bitcoin"][!UpdateMeasureGroup "Bitcoin"]
DynamicVariables=1
Disabled=1
[Bitcoin1hour]
Measure=Plugin
Plugin=WebParser
URL=[Bitcoin]
StringIndex=1
Disabled=1
Group=Bitcoin
[Bitcoin24hour]
Measure=Plugin
Plugin=WebParser
URL=[Bitcoin]
StringIndex=2
Disabled=1
Group=Bitcoin
[Bitcoin7days]
Measure=Plugin
Plugin=WebParser
URL=[Bitcoin]
StringIndex=3
Disabled=1
Group=Bitcoin
[BitcoinValueEuro]
Measure=Plugin
Plugin=WebParser
URL=[Bitcoin]
StringIndex=4
Disabled=1
Group=Bitcoin
[MeterBitcoin]
Meter=STRING
MeasureName=BitcoinValueEuro
MeasureName2=Bitcoin1hour
MeasureName3=Bitcoin24hour
MeasureName4=Bitcoin7days
X=0
Y=50
Padding=15,5,15,5
FontColor=220,220,220
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=Euro price: %1#CRLF#Percent change 1h: %2#CRLF#Percent change 24h: %3#CRLF#Percent change 7d: %4
DynamicVariables=1
-
- Posts: 3
- Joined: September 26th, 2017, 5:21 pm
Re: getting lost in the basics of the WebParser
Thanks a lot for your help! The first test seems really good, so I can move forward with the build. The code makes sense so hopefully I can re-use it for other means within the skin. Just getting started so it will take some time before I understand all of it and finish the skin.
-
- Moderator
- Posts: 1387
- Joined: April 11th, 2013, 8:08 pm
- Location: Italy
Re: getting lost in the basics of the WebParser
Sorry balala, but... unless you want to save the file for further use, why use Download=1?balala wrote:...
The following code uses this approach: first the [MeasureBitcoin] measure downloads the file (due to its Download=1 option). At this point all other WebParser measures are disabled. When the download is finished, the FinishAction option of this measure enables and updates the [Bitcoin] measure, which is the parent measure. This measure will parse the data. When it finishes, will enable the child measures (I included those measures into a group, named Bitcoin), which will return the needed data...
You can simply save it in memory and read it with the child measures.
-
- Rainmeter Sage
- Posts: 16168
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: getting lost in the basics of the WebParser
Glad to help. Be sure it'll take some time, but if you keep working, you can improve your knowledge and your codes.EvilUnicorn wrote:Thanks a lot for your help! The first test seems really good, so I can move forward with the build. The code makes sense so hopefully I can re-use it for other means within the skin. Just getting started so it will take some time before I understand all of it and finish the skin.
The biggest problem of your initial code is that it used four parent WebParser measures, all of them downloading the file / parsing the data. This means four times the same operation, which is not a good idea. The administrator of the site seeing an increased data trafic from your address, can block your IP, which will make the skin to not work any more (details). If you're using one single parent measures and as many child measures as you want (up to 99), you can avoid this situation.
-
- Rainmeter Sage
- Posts: 16168
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: getting lost in the basics of the WebParser
Could you please post a working code?fonpaolo wrote:Sorry balala, but... unless you want to save the file for further use, why use Download=1?
You can simply save it in memory and read it with the child measures.
-
- Moderator
- Posts: 1387
- Joined: April 11th, 2013, 8:08 pm
- Location: Italy
Re: getting lost in the basics of the WebParser
Even though my last skins I have created using WebParser, which are more than two years old, you can take a look at them.
However, the code is simple:
- use a measure to download all, let's say:
- then use a first child to parse some data:
- and so many child measures to display all you want:
...and so on.
The only difference, is I don't use Download=1 in the first WebParser measure.
However, the code is simple:
- use a measure to download all, let's say:
Code: Select all
[MeasureBase]
Measure=WebParser
Url=https://whatever...
RegExp=(?siU)^(.*)$
UpdateRate=1800
FinishAction=[!UpdateMeasure MeasureSubBase][!UpdateMeasureGroup XYZ]
Code: Select all
[MeasureSubBase]
Measure=WebParser
Url=[MeasureBase]
RegExp=(?siU).* (.*) ... (.*) ...
StringIndex2=(if needed)
UpdateDivider=-1
Code: Select all
[MeasureWhatever1]
Measure=WebParser
Url=[MeasureSubBase]
StringIndex=1
UpdateDivider=-1
Group=XYZ
[MeasureWhatever2]
Measure=WebParser
Url=[MeasureSubBase]
StringIndex=2
UpdateDivider=-1
Group=XYZ
The only difference, is I don't use Download=1 in the first WebParser measure.