It is currently April 27th, 2024, 4:26 pm

WebParser: Local Files and inserting the parsing result into the URL.

Get help with creating, editing & fixing problems with skins
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: WebParser: Local Files and inserting the parsing result into the URL.

Post by eclectic-tech »

[mCod] has no value when the skin is first loaded, so [mTotal] will not work.
You need to "Update" the [mTotal] when [mCod] finishes to be able to use it's value.

See: DynamicVariable use in Webparser

Also, whenever you use Section Variables you must add DynamicVariables=1 to the section. This was missing from your [mTotal] section.

This code adds a FinishAction to [mCod] so it updates [mTotal] after [mCod] has a value and adds DynamicVariables=1 to [mTotal].

I also corrected the synax to use the measure value of [mCod]; not a variable named [#[&mCod]] since I did not see any code where you set that variable value. :uhuh:

Code: Select all

[mCod]
Measure=WebParser
Url=file://#CURRENTPATH#Settings.inc
RegExp="(?siU)weather-.*-(.*)/.*"
stringindex=1
DynamicVariables=1
FinishAction=[!CommandMeasure mTotal "Update"]

[mTotal]
Measure=WebParser
UpdateRate	=3600
Url			=https://services.gfore.net/inform-service/#hash_val#/forecast/?lang=#lang#&city=[&mCod]
UserAgent	=#uagent#
RegExp		="(?siU)<location(.*)</location>"
DynamicVariables=1
Kotofanchik
Posts: 95
Joined: March 15th, 2024, 7:30 pm

Re: WebParser: Local Files and inserting the parsing result into the URL.

Post by Kotofanchik »

Yes, it worked. Miracle. I still can’t understand these things myself. Thank you
I can only add different brackets, quotes, hashtags, ampersands and other magical things and update the skin, expecting it to work. :)
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: WebParser: Local Files and inserting the parsing result into the URL.

Post by eclectic-tech »

Understanding what affect all of those symbols have can be confusing, but this forum, the documentation, and the !About Log are you best references to find solutions.

Glad you got it working. :thumbup:
User avatar
Yincognito
Rainmeter Sage
Posts: 7177
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser: Local Files

Post by Yincognito »

Kotofanchik wrote: March 27th, 2024, 4:03 am This doesn’t help, I did as it was written and as it was not written and 25 more options and nothing works. :D

Code: Select all

[mCod]
Measure=WebParser
Url=file://#CURRENTPATH#Settings.inc
RegExp="(?siU)weather-.*-(.*)/.*"
stringindex=1
DynamicVariables=1

[mTotal]
Measure=WebParser
UpdateRate	=3600
Url			=https://services.gfore.net/inform-service/#hash_val#/forecast/?lang=#lang#&city=[#[&mCod]]
UserAgent	=#uagent#
RegExp		="(?siU)<location(.*)</location>"
Measure [mCod] now works, but [mTotal] doesn't work
WebParser measures will NOT provide data immediately, but only as soon as the URL resource has been parsed successfully. In addition to that, they will NOT request the URL resource until the UpdateRate moment comes OR the measure has been commanded to update via [!CommandMeasure SomeWebParser "Update"] and such. Another detail, this time true not just for WebParser measures, but for every dynamic section variable (e.g. measure or variable used elsewhere), is that referencing it will only work if you add a DynamicVariables=1 to the section where you use that value, to account for changes in the value.

In practice, this means your code is never going to work the way you wrote it. mCod will get its value fine, but will do so AFTER both mCod AND mTotal already updated to request their URL resource. In other words, [&mCod] will be the empty string at the time of mTotal's request, because its value wasn't retrieved yet and even if it were, DynamicVariables wasn't enabled in mTotal.

The solution is to command mTotal to update (see above) from the FinishAction of mCod (which you'll have to add, of course), along with moving the DynamicVariables line from mCod (where it's not really needed at this point, since, after all, #CURRENTPATH# is not changing its value dynamically) to mTotal. Also, as far as your code looks, using [&mCod] is enough, since nesting it into [#[&mCod]] will actually reference a variable whose name is the value of mCod, something not needed here.
Well, eclectic-tech tech beat me with the above, but you can still read WHY such things happened, if interested.

By the way, WebParser CAN parse an UTF-16LE BOM file, if you adjust the CodePage option of that WebParser, as explained in that option's entry from the WebParser page in the manual:
https://docs.rainmeter.net/manual/measures/webparser/

That being said, KazukiGames82 was right, if the mCod value is stored as a variable in your Settings.inc file, then using the @include option is much more suited in such a case.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
Kotofanchik
Posts: 95
Joined: March 15th, 2024, 7:30 pm

Re: WebParser: Local Files and inserting the parsing result into the URL.

Post by Kotofanchik »

Yes, we need to study it. All these subtleties.
Can you give an example about @include? otherwise maybe it doesn’t reach me.
In my settings file I have the address of a weather site, and part of this address contains this code. I can get it from the site, but the site sometimes does not respond. And weather data continues to be provided from the api
User avatar
Yincognito
Rainmeter Sage
Posts: 7177
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser: Local Files and inserting the parsing result into the URL.

Post by Yincognito »

Kotofanchik wrote: March 27th, 2024, 1:37 pm Yes, we need to study it. All these subtleties.
Can you give an example about @include? otherwise maybe it doesn’t reach me.
In my settings file I have the address of a weather site, and part of this address contains this code. I can get it from the site, but the site sometimes does not respond. And weather data continues to be provided from the api
An example is already given at the bottom of the @include page from the manual:
https://docs.rainmeter.net/manual/skins/include-option/

You just need to adapt it to your needs, e.g.

Settings.inc:

Code: Select all

[Variables]
cod=cod123
...
YourSkin.ini:

Code: Select all

[Variables]
@IncludeSettings=#CURRENTPATH#Settings.inc
...

[mTotal]
Measure=WebParser
UpdateRate	=3600
Url			=https://services.gfore.net/inform-service/#hash_val#/forecast/?lang=#lang#&city=#cod#
UserAgent	=#uagent#
RegExp		="(?siU)<location(.*)</location>"
DynamicVariables=1
No need to store the entire address in the cod variable from Settings.inc (just the "cod" itself would be fine), and no need for the [mCod] measure anymore (since we already have the equivalent variable @included). Probably no need for the DynamicVariables=1 line either, but I left it there just in case one of those variables changes at some point.

Basically, no need to complicate ourselves with WebParser measures if it's just about some variables. The WebParser measures can obviously be used as well, but for more complex stuff, like parsing an entire text file for values needing more work to find them, that kind of things.

P.S. If at some point you change the value of your "cod" variable (via either !SetVariable to do it in memory, or !WriteKeyValue to physically store it in your Settings.inc file), commanding mTotal to "Update" will still be needed, in order to request data from the site using the new "cod" value.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
Kotofanchik
Posts: 95
Joined: March 15th, 2024, 7:30 pm

Re: WebParser: Local Files and inserting the parsing result into the URL.

Post by Kotofanchik »

A strange effect was discovered, it works once when loading Rainmeter and then that’s it. Does not work. Second strange effect. Not all data is obtained from the API. If I enter the code manually, then that’s it, but this way only part of it. Moreover, mTotal receives a complete data package. but the messages below that receive data from mtotal do not all work
Kotofanchik
Posts: 95
Joined: March 15th, 2024, 7:30 pm

Re: WebParser: Local Files and inserting the parsing result into the URL.

Post by Kotofanchik »

Yincognito wrote: March 27th, 2024, 2:00 pm

No need to store the entire address in the cod variable from Settings.inc (just the "cod" itself would be fine), and no need for the [mCod] measure anymore (since we already have the equivalent variable @included). Probably no need for the DynamicVariables=1 line either, but I left it there just in case one of those variables changes at some point.

Basically, no need to complicate ourselves with WebParser measures if it's just about some variables. The WebParser measures can obviously be used as well, but for more complex stuff, like parsing an entire text file for values needing more work to find them, that kind of things.
That's exactly how it was before. but people can’t find this "cod" themselves, and I’m tired of explaining how to see it there, but they successfully copy the full site address line into a file where Regexp finds the "cod" in it
User avatar
Yincognito
Rainmeter Sage
Posts: 7177
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser: Local Files and inserting the parsing result into the URL.

Post by Yincognito »

Kotofanchik wrote: March 27th, 2024, 2:11 pm A strange effect was discovered, it works once when loading Rainmeter and then that’s it. Does not work. Second strange effect. Not all data is obtained from the API. If I enter the code manually, then that’s it, but this way only part of it. Moreover, mTotal receives a complete data package. but the messages below that receive data from mtotal do not all work
See the P.S. from my previous reply, if it's related to that. Otherwise, you need to explain better what you experience or want, because it's hard to follow what you mean (I know, translating is a b..h), especially considering that you didn't share the entire code but only parts of it. :confused:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7177
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WebParser: Local Files and inserting the parsing result into the URL.

Post by Yincognito »

Kotofanchik wrote: March 27th, 2024, 2:20 pm That's exactly how it was before. but people can’t find this "cod" themselves, and I’m tired of explaining how to see it there, but they successfully copy the full site address line into a file where Regexp finds the "cod" in it
Oh, now I see where the problem is - you still want to find the "cod" in the site's address. Well, if that's the case, you can use WebParser as before. You could use @include as above too, store the entire address in the variable, then use a RegExpSubstitute=1 / Substitute in a String measure to which you pass the value of the variable, to extract only the "cod" from that variable, but it's more or less the same thing as using the WebParser approach.

In any case, I still think you're overcomplicating things, but well, if it works, then it should do it.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth