-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextra.py
31 lines (26 loc) · 1002 Bytes
/
textra.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
import argparse
import requests
from requests_oauthlib import OAuth1
def trans():
parser = argparse.ArgumentParser()
parser.add_argument('--name', default='tra', help='User ID')
parser.add_argument(
'--key', default='dc8f758149be1e05fec938b7e1aa829f06308ffe1')
parser.add_argument('--secret', default='cb508033fe4c5ddd9744b1aa82589a98')
parser.add_argument('-e', '--engine', default='generalNT')
parser.add_argument('-s', '--source', default='en')
parser.add_argument('-t', '--target', default='ja')
parser.add_argument('text')
args = parser.parse_args()
url = f'https://mt-auto-minhon-mlt.ucri.jgn-x.jp/api/mt/{args.engine}_{args.source}_{args.target}/'
data = {
'key': args.key,
'name': args.name,
'text': args.text,
'type': 'json'
}
r = requests.post(url, data=data, auth=OAuth1(
args.key, args.secret)).json()
print(r['resultset']['result']['text'])
if __name__ == '__main__':
trans()