-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzoom.py
54 lines (40 loc) · 1.65 KB
/
zoom.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
# Zoom captioning api wrapper (and google translate)
# Written (Copy-pasted) by Arttu Mahlakaarto
import requests
import time
import six
from google.cloud import translate_v2 as translate
import html
class cc_api():
def __init__(self):
self.url="%ZOOM-TOKEN-PLACEHOLDER%&lang=en-US" # TODO: read from input or from file, too tired to implement tonight.
self.seq=0
self.translate_client = translate.Client()
def send_cc(self,cc):
try:
req = requests.post(self.url + "&seq=" + str(self.seq),data=cc.encode('utf-8'),headers={"Content-Type": "text/plain"})
except:
print("fail")
time.sleep(0.04)
try:
req = requests.post(self.url + "&seq=" + str(self.seq),data=cc.encode('utf-8'),headers={"Content-Type": "text/plain"})
except:
return
print(req.text)
def confirm(self,cc):
c1=self.translate_text(cc.encode('utf-8'))+"\n"
req = requests.post(self.url + "&seq=" + str(self.seq),data=c1.encode('utf-8'),headers={"Content-Type": "text/plain"})
self.seq+=1
f = open("seq.tmp", "w")
f.write(self.seq)
f.close()
print(req.text)
return
def translate_text(self, text):
if isinstance(text, six.binary_type):
text = text.decode("utf-8")
# Text can also be a sequence of strings, in which case this method
# will return a sequence of results for each text.
result = self.translate_client.translate(text, target_language="en",source_language="fi")
print
return(html.unescape(result["translatedText"]))