It is currently April 19th, 2024, 9:58 pm

Parsing Variable text files or writing JSON files

Get help with installing and using Rainmeter.
yeeha68
Posts: 2
Joined: December 16th, 2018, 11:02 am

Parsing Variable text files or writing JSON files

Post by yeeha68 »

I need to parse files from other computers on my network. I am familiar with this process via JSON format, but I need the other computers on the network to write the JSON files via Rainmeter installed on each.

Writing the file is simple enough using;
[!WriteKeyValue Variables listen OFF "variables.inc"]

But it will only write a file that is not in JSON format, and I cannot figure out how to parse this text file.
I get this;
[Variables]
listen=OFF

I need this;
{"listen":"OFF"}

This needs to be a dynamic switch so I can monitor the status of the network.
Is there a way to 1. write in JSON or XML format, OR 2. Parse this text file.
-thanks
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Parsing Variable text files or writing JSON files

Post by balala »

yeeha68 wrote: December 16th, 2018, 11:17 am OR 2. Parse this text file.
Parsing a text file is easy, using WebParser measures. Something like this:

Code: Select all

[MeasureJSON]
Measure=WebParser
URL=file://C:\MyFile.txt
RegExp=(?siU)\{"listen":"(.*)"}
StringIndex=1
This will return the listen variable. Take care to modify the URL option, to point to your file.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Parsing Variable text files or writing JSON files

Post by jsmorley »

Rainmeter cannot write XML files. It can't write to any files except INI formatted files, and they must be in the ..Rainmeter\Skins folder structure.

Anything else is going to require some reasonably complicated Lua scripting.

Rainmeter is a single-user, single computer, home hobbyist tool, and is not designed for, nor encouraged in, a shared or business network environment.
yeeha68
Posts: 2
Joined: December 16th, 2018, 11:02 am

Re: Parsing Variable text files or writing JSON files

Post by yeeha68 »

So I got it to work with this parse format:

ini file written by Rainmeter;
[Variables]
listen=OFF
hear=ON
end=END

Parse format;
(?siU)listen=(.*).hear=(.*).end(.*)

Thus;
1 => OFF
2 => ON

syntax was messy and then I realized I needed a close "end" to get the two "listen" and "hear" variables.

So, yes, it is possible to parse a dynamic INI written by Rainmeter.