Skip to content

Commit

Permalink
added file long
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianWww committed Mar 5, 2023
1 parent 5294ceb commit 821fd38
Show file tree
Hide file tree
Showing 4 changed files with 726 additions and 692 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ libs/automatone-0.9.0.jar
generators/token/tmp/
generators/lang/TableIt.py
generators/lang/Tor/
generators/lang/out.log
38 changes: 35 additions & 3 deletions generators/lang/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,49 @@
'https': 'socks5://127.0.0.1:9050'
}

log = open("out.log", "w")

def file_print(*args, **kwargs):
print(*args, file=log, flush=True, **kwargs)

def remove_last_line():
global log
log.close()
with open("out.log", "r") as file:
lines = file.readlines()

log = open("out.log", "w")
log.writelines(lines[:-1])

def printProgress(done, todo, time):
if (done > 0):
remove_last_line()
file_print(f"{done} / {todo} \t\t {time} s")


def translate(orig, dest):
#runTor()
translator = GoogleTranslator(source='en', target=dest, proxies=PROXIES)
s = time()

try:
out = {x: translator.translate(y) for x, y in orig.items()}
except:
out = {}
for idx, (x, y) in enumerate(orig.items()):
printProgress(idx, len(orig), time() - s)
s = time()
out[x] = translator.translate(y)
except Exception as e:
sleep(0.2)
file_print(f"TRANSLATION FAILED {e}")
return translate(orig, dest)

return out

def makeTranslation(transKey, filenames):
s = time()

file_print(f"Translating to {transKey}")

if isinstance(filenames, str):
filenames = [filenames]

Expand All @@ -48,6 +75,8 @@ def makeTranslation(transKey, filenames):
for filename in filenames:
with open(f"{langDir}{filename}.json", "w") as file:
dump(data, file, indent=4, sort_keys=True)

file_print(f"Translated to {transKey} {time() - start} s")

langTimeTable.append([transKey, f"{int(time() - start)} s"])

Expand All @@ -63,7 +92,10 @@ def makeTranslation(transKey, filenames):
dump(langs, file, indent=4, sort_keys=True)


for args in langs.items():
for idx, args in enumerate(langs.items()):
file_print(idx, end="")
makeTranslation(*args)

print(langTimeTable)

log.close()
4 changes: 2 additions & 2 deletions generators/lang/langs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"ar": "ar_sa",
"az": "az_az",
"be": "be_by",
"bg": "bg_bg",
"bg": "bg_bg",
"bs": "bs_ba",
"ca": "ca_es",
"cs": "cs_cz",
Expand Down Expand Up @@ -127,4 +127,4 @@
"zh_hk",
"zh_tw"
]
}
}
Loading

0 comments on commit 821fd38

Please sign in to comment.