Added a parser to scrap additional information for the esp-edge and added json-snippets for ts-nodes
This commit is contained in:
committed by
Martin Jäger
parent
0e8f93bc08
commit
824e33f4e8
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
|
||||
output_path = "info.json"
|
||||
json_str = ""
|
||||
main_obj = {}
|
||||
temp_obj = {}
|
||||
current_key = ""
|
||||
name = ""
|
||||
beginning_line = 0
|
||||
save_lines = False
|
||||
save_name = False
|
||||
|
||||
def append_stuff(temp_obj):
|
||||
if current_key != "":
|
||||
main_obj[current_key] = temp_obj.copy()
|
||||
temp_obj.clear()
|
||||
|
||||
with open("src/data_nodes.cpp", 'r') as fd:
|
||||
for (num, line) in enumerate(fd, 1):
|
||||
if line =="\n":
|
||||
continue
|
||||
if "TS_NODE_PATH" in line:
|
||||
if current_key != "":
|
||||
append_stuff(temp_obj)
|
||||
|
||||
current_key = line.strip().split(",")[1].strip(' "')
|
||||
continue
|
||||
|
||||
if (line.strip(" \n") == "/*{"):
|
||||
save_lines = True
|
||||
beginning_line = num
|
||||
json_str +="{"
|
||||
continue
|
||||
elif (line.strip(" \n") == "}*/"):
|
||||
json_str += "}"
|
||||
save_lines = False
|
||||
save_name = True
|
||||
continue
|
||||
|
||||
if save_lines:
|
||||
json_str += line
|
||||
|
||||
if save_name:
|
||||
try:
|
||||
name = line.strip().split(",")[1].strip(' "')
|
||||
temp_obj[name] = json.loads(json_str)
|
||||
except Exception as e:
|
||||
print("Error while parsing block between lines {} and {}".format(beginning_line, num))
|
||||
print(e)
|
||||
exit(-1)
|
||||
save_name = False
|
||||
json_str = ""
|
||||
|
||||
append_stuff(temp_obj)
|
||||
|
||||
with open(output_path, "w", encoding='utf8') as filename:
|
||||
json.dump(main_obj, filename, indent=4, ensure_ascii=False)
|
||||
|
||||
print("Saved file under: " + output_path)
|
||||
+937
-4
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user