Skip to content

Commit b7918b4

Browse files
committed
Add helper script
1 parent 482f698 commit b7918b4

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

scripts/plzdata.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import base64
2+
import json
3+
import sys
4+
from pathlib import Path
5+
6+
encrypted_filename = Path("./assets/plz.json")
7+
decrypted_filename = Path("./assets/plz-plain.json")
8+
9+
10+
def decrypt():
11+
with open(encrypted_filename) as f:
12+
data = json.load(f)
13+
data = [
14+
{**x, **{"E-Mail": base64.b64decode(x["E-Mail"]).decode("utf-8")}} for x in data
15+
]
16+
with open(decrypted_filename, "w") as f:
17+
json.dump(data, f, ensure_ascii=False, indent=2)
18+
19+
20+
def encrypt():
21+
with open(decrypted_filename) as f:
22+
data = json.load(f)
23+
data = [
24+
{
25+
**x,
26+
**{"E-Mail": base64.b64encode(x["E-Mail"].encode("utf-8")).decode("utf-8")},
27+
}
28+
for x in data
29+
]
30+
with open(encrypted_filename, "w") as f:
31+
json.dump(data, f, ensure_ascii=False, indent=2)
32+
33+
34+
if __name__ == "__main__":
35+
arg = sys.argv[1]
36+
if arg == "decrypt":
37+
decrypt()
38+
elif arg == "encrypt":
39+
encrypt()
40+
else:
41+
print("Bad argument")

0 commit comments

Comments
 (0)