@CalebEvans1/

Terrible Translator

Python

No description

fork
loading
Files
  • main.py
  • Accesses.txt
main.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
54
55
56
57
58
59
60
61
62
63
64
from time import sleep
import googletrans
import random, time

def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█'):
    """
    Call in a loop to create terminal progress bar
    @params:
        iteration   - Required  : current iteration (Int)
        total       - Required  : total iterations (Int)
        prefix      - Optional  : prefix string (Str)
        suffix      - Optional  : suffix string (Str)
        decimals    - Optional  : positive number of decimals in percent complete (Int)
        length      - Optional  : character length of bar (Int)
        fill        - Optional  : bar fill character (Str)
    """
    percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
    filledLength = int(length * iteration // total)
    bar = fill * filledLength + ' ' * (length - filledLength)
    print('\x1b7\x1b[6;1f\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end = '\r\n')
    # Print New Line on Complete
    if iteration == total: 
        print()

translate_urls = ["translate.google.com", "translate.google.co.kr",
                      "translate.google.at", "translate.google.de",
                      "translate.google.ru", "translate.google.ch",
                      "translate.google.fr", "translate.google.es"]

yet = googletrans.Translator(service_urls=translate_urls)

def translater(langn, textn):
    return yet.translate(text=textn,dest=langn).text

iters = int(input("Number of languages to translate through: "))
iterText = input("Text to translate: ")

if len(iterText) > 15*1024:
    iterText = iterText[:15*1024]

lans = list(googletrans.LANGUAGES.keys())

items = []
# A List of Items
if iters > len(lans):
    for i in range(iters):
        items.append(random.choice(lans))
else:
    items = lans[:iters]
l = len(items)
with open("Accesses.txt", "a") as f:
    f.write(str(time.time())+' | '+str(iters).ljust(20)+' | '+iterText+'\n')

# Initial call to print 0% progress
printProgressBar(0, l, length = 100, decimals = 3)
for i in range(len(items)):
    iterText = translater(items[i], iterText)
    #sleep(5)
    # Update Progress Bar
    printProgressBar(i + 1, l, length = 100, decimals = 3)
    print('\x1b7\x1b[7;1f'+iterText+'                        '+'\n'+translater('en',iterText)+'                             ')