-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestClient.py
executable file
·75 lines (54 loc) · 2.39 KB
/
TestClient.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
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
sys.path.append('./gen-py')
import os
import logging
from logging import handlers
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TCompactProtocol
from LanguageTranslationService.ttypes import *
import LanguageTranslationService.LTService as lts
from LanguageTranslator import LanguageTranslator
CURRENT_PATH = os.path.realpath(os.path.dirname(__file__))
LOG_DIR = os.path.join(CURRENT_PATH, 'logs')
LOG_FILE = os.path.join(LOG_DIR, 'logget.log')
LOG_LEVEL = logging.INFO
FORMAT = ('%(asctime)s\t%(message)s')
DATE_FORMAT = '%d-%m-%Y %H:%M:%S'
if not os.path.exists(LOG_DIR):
os.mkdir(LOG_DIR)
logging.basicConfig(level=logging.DEBUG, format=FORMAT, datefmt=DATE_FORMAT)
fileHandler = logging.handlers.RotatingFileHandler(filename = LOG_FILE, mode='a+', maxBytes = 1000000, backupCount = 1)
fileHandler.setFormatter(logging.Formatter(FORMAT, datefmt =DATE_FORMAT))
logging.getLogger().addHandler(fileHandler)
log = logging.getLogger(__name__)
# Метод проверяет работу сервиса переводов
def RunTest():
l log.info("run test")
host = 'localhost'
port = 9900
# Настраиваем соединение
transport = TSocket.TSocket(host, port)
transport = TTransport.TBufferedTransport(transport)
protocol = TCompactProtocol.TCompactProtocol(transport)
client = lts.Client(protocol)
# Открываем соединение
transport.open()
# Получаем перевод
translatePackage = client.Translate(u"Kingdoms")
# Выводим все поля у полученной структуры с результатом перевода
print "Word:\t\t%s" % (translatePackage.word)
print "Lemma:\t\t%s" % (translatePackage.lemma)
print "Part Of Speech:\t%s" % (PartOfSpeech.ValueToNames[translatePackage.partOfSpeech])
for item in translatePackage.translations:
print "#######################################################"
print "Name of the Dictionary:\t%s" % (item.nameDictionary)
print "Sequence Type:\t%s" % (item.sameTypeSequence)
print "Translate:\t%s" % (item.translate)
# Закрываем соединение
transport.close()
if __name__ == "__main__":
RunTest()