-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.py
More file actions
64 lines (49 loc) · 1.57 KB
/
exec.py
File metadata and controls
64 lines (49 loc) · 1.57 KB
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
#coding: utf-8
from microsofttranslator import Translator, TranslateApiException
import os
import glob
import codecs
client_id = "<CLIENT_ID>"
client_secret = "<SECRET_KEY>"
client = Translator(client_id, client_secret, debug=True)
print()
filename = 'install.srt'
fileTraduzido = '';
def isNoneOrEmptyOrBlankString(myString):
if myString:
if not myString.strip():
return True
else:
return True
return False
def traduzir(string):
return client.translate(string, "pt")
def criarDiretorio():
if not os.path.exists('PT'):
os.makedirs('PT')
def is_number(s):
try:
float(s)
return True
except ValueError:
return False
def processarArquivo(nomeArquivo):
fileTraduzido = open(os.path.dirname(os.path.abspath(__file__))+'\\PT\\'+nomeArquivo, 'w')
with open(nomeArquivo) as openfileobject:
for line in openfileobject:
if "0" != line[0] \
and "[MUSIC]" != line[0] \
and not isNoneOrEmptyOrBlankString(line) \
and not is_number(line[0]):
textoTraduzido = traduzir(line)
fileTraduzido.write(textoTraduzido.encode('utf8'))
print(textoTraduzido.encode('utf-8'))
else:
print line;
fileTraduzido.write(line)
fileTraduzido.close()
criarDiretorio()
arquivos = glob.glob("*.vtt")
print(os.path.dirname(os.path.abspath(__file__)))
for x in arquivos:
processarArquivo(x)