-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_json.py
53 lines (30 loc) · 927 Bytes
/
read_json.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
51
52
53
import sys
import os
import json
import deepl
import textwrap
fn = sys.argv[1]
f = open(fn, "r+")
data = json.load(f)
current_loc = data["current_loc"]
sentences = data["segments"]
translator = deepl.Translator(os.environ["DEEPL_API"])
for sentence in sentences[current_loc:]:
term_width = os.get_terminal_size().columns
print("\n" + textwrap.fill(sentence, term_width) + "\n\n" + ("-" * term_width) + "\n")
x = input()
while x:
if x == "exit":
exit()
else:
print("\n" + translator.translate_text(x, target_lang="EN-US").text + "\n")
x = input()
print("\n" + textwrap.fill(translator.translate_text(sentence, target_lang="EN-US").text, term_width) + "\n\n" + ("-" * term_width) + "\n")
if input() == "exit":
exit()
else:
current_loc += 1
data["current_loc"] = current_loc
f.seek(0)
json.dump(data, f)
f.truncate()