It is currently March 24th, 2019, 7:53 am

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

yeeha68 » December 16th, 2018, 11:17 am

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: 7907
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Parsing Variable text files or writing JSON files

balala » December 16th, 2018, 12:59 pm

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: 19072
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Parsing Variable text files or writing JSON files

jsmorley » December 16th, 2018, 1:33 pm

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

yeeha68 » December 16th, 2018, 6:44 pm

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.