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
It is currently May 2nd, 2024, 11:20 pm
Parsing Variable text files or writing JSON files
-
- Posts: 2
- Joined: December 16th, 2018, 11:02 am
-
- Rainmeter Sage
- Posts: 16195
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Parsing Variable text files or writing JSON files
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
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Parsing Variable text files or writing JSON files
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.
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.
-
- Posts: 2
- Joined: December 16th, 2018, 11:02 am
Re: Parsing Variable text files or writing JSON files
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.
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.