It is currently March 29th, 2024, 12:12 am

parsing a txt file with only one string returns nothing

Get help with creating, editing & fixing problems with skins
1Try
Posts: 3
Joined: October 9th, 2022, 6:45 am

parsing a txt file with only one string returns nothing

Post by 1Try »

Thank you for your help and time.

I'm trying to parse a txt file that contains only one string (an url).

The txt file is created via a python script and the url is variable, so i cannot feed it directly into the rainmeter code.

Then, this url is then passed to another parser

Here's the problem:

Code: Select all

[raw]
Measure=Plugin
Plugin=WebParser
Url = file://#CURRENTPATH#raw.txt
Regex=(?siU)[\s\S]+
StringIndex=1

[apiReturn]
Measure=Plugin
Plugin=WebParser
Url=raw
StringIndex=1

I already tried with no regex, and current regex was also validated with the "RainRegExp" recommended program to the text file.
Supossed it should return the only string inside the txt file.
For debugging purposes I'm using https://www.google.com as the only line of text


The debug log shows:

Code: Select all

[raw]: Fetching: file://S:\Documents\Rainmeter\Skins\test\raw.txt
[raw]: Fetching: Success!
[raw]: Parsing data...
[raw]: Not enough substrings
[raw]: Parsing data...done!
Last edited by 1Try on October 9th, 2022, 1:25 pm, edited 2 times in total.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: parsing a txt file with only one string returns nothing

Post by balala »

1Try wrote: October 9th, 2022, 7:03 am I'm trying to parse a txt file that contains only one string (an url).
The posted measures have more issues:
  • The name of the measure used in the URL option of a child WebParser measure (in this case the [apiReturn] measure) has to be included into brackets. So replace the Url option of this measure with Url=[raw].
  • A Regex option doesn't exist (you've used it on the [raw] measure). Add the missing p to the end of the option name: RegExp (see below as well).
  • In the RegExp option what the measure(s) should return have to be included into parenthesis. That's why you have to add such parenthesis around the [\s\S]+ parameter of this option. Something like this: Regexp=(?siU)([\s\S]+).
  • If you want the measure to return the whole string, add the character representing the beginning and the end of the string. This way for instance: Regexp=(?siU)^([\s\S]+)$.
Additionally there are two other issues as well, which don't prevent the code to work, however should be fixed:
  • Even if a while ago WebParser was a plugin, in meantime it has been converted to an internal measure. Accordingly the measures should never be used as Plugin measures, but as WebParser measures. So recommend replacing the Measure=Plugin and Plugin=WebParser options of the measures by Measure=WebParser (however nore that for beackward compatibility reasons the Plugin statement still works).
  • When using a parent - child measure structure for WebParser measures (like you did), the parent measure (in this case [raw]), shouldn't have a StringIndex set. Remove the StringIndex=1 option from this measure.
With these modifications, the working measures should look for example this way:

Code: Select all

[raw]
Measure=WebParser
Url=file://#CURRENTPATH#raw.txt
RegExp=(?siU)^([\s\S]+)$

[apiReturn]
Measure=WebParser
Url=[raw]
StringIndex=1
1Try
Posts: 3
Joined: October 9th, 2022, 6:45 am

Re: parsing a txt file with only one string returns nothing

Post by 1Try »

Thank you so much, It worked!
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: parsing a txt file with only one string returns nothing

Post by balala »

1Try wrote: October 9th, 2022, 1:25 pm Thank you so much, It worked!
:thumbup: