-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathr-stack-filter.py
More file actions
executable file
·31 lines (26 loc) · 1007 Bytes
/
r-stack-filter.py
File metadata and controls
executable file
·31 lines (26 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
import json
import sys
def process_json(data):
if isinstance(data, list):
for item in data:
process_json(item)
elif isinstance(data, dict):
#if "t" in data and data["t"] == "Div" and "r-stack" in data.get("c", []):
if "t" in data and data["t"] == "Div" and isinstance(data.get("c", []), list) and len(data["c"]) > 1 and "r-stack" in data["c"][0][1]:
if data["c"][1][0]["t"] == "Para":
data["c"][1][0]["t"] = "Plain"
else:
for key, value in data.items():
process_json(value)
if __name__ == "__main__":
# Read JSON data from stdin as text
input_json_text = sys.stdin.read()
try:
input_json = json.loads(input_json_text)
except json.JSONDecodeError as e:
print("Error decoding JSON:", e, file=sys.stderr)
sys.exit(1)
process_json(input_json)
# Print the modified JSON to stdout
json.dump(input_json, sys.stdout, indent=2)