-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader.py
50 lines (47 loc) · 1.84 KB
/
reader.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import gzip
import base64
import json
from tkinter import Tk
import sys
try:
jsond = json.loads(Tk().clipboard_get().replace(";", ":"))
except:
print("Please click on the Copy text")
sys.exit(1)
data = jsond["code"]
b = base64.b64decode(data)
r = json.loads(gzip.decompress(b).decode())
indents = 0
for i in r["blocks"]:
isBlock = i["id"]
ind = "\t" * indents
if isBlock == "block":
block = i["block"]
if block in {"func", "process"}: # 2nd time i've used a set in any language
btype = i["data"]
elif block == "else":
print(f"\n{ind} else", end="")
else:
btype = i["action"]
allItems = i["args"]["items"]
items = list(filter((lambda j: j["item"]["id"] != "bl_tag"), allItems))
tags = list(filter((lambda j: j["item"]["id"] == "bl_tag"), allItems))
items.sort(key=(lambda j: j["slot"]))
tags.sort(key=(lambda j: j["slot"]))
# below is the longest lambda known to man
itemDisps = list(map((lambda j: j["item"]["id"] + " | " + str(j["item"]["data"] if j["item"]["id"] != "item" else j["item"]["data"]["item"][(j["item"]["data"]["item"].find("id:") + 3):j["item"]["data"]["item"].find(",tag")])), items))
tagDisps = list(map(lambda j: j["item"]["data"]["tag"] + ": " + j["item"]["data"]["option"], tags))
itemDisps = str(itemDisps).replace("'", "")
if len(tagDisps) == 0:
tagDisps = ""
else:
tagDisps = str(tagDisps).replace("'", "")
print(f"\n{ind}{block}: {btype} {itemDisps} {tagDisps}", end=" ")
else:
if i["direct"] == "open":
print(" {", end=" ")
indents += 1
else:
indents -= 1
ind = "\t" * indents
print(f"\n{ind}}}", end="")