[Sync] Kazimir uses ALS Typograf

This commit is contained in:
Roman Timashev committed 2017-10-16 03:16:12 +03:00
1 parent 3ecf1deb5d
commit a034254cbe
2 files changed
+48 -3

No files matched your search

+5 -3
View File
@@ -94,9 +94,11 @@ def html_from_tree(tree):
async def typo(text):
url = 'http://www.typograf.ru/webservice/'
params = dict(text=text)
return await request.post(url, params, {'chr': 'utf-8'})
from kazimir import artlebedev
return await artlebedev.typograf(text)
# url = 'http://www.typograf.ru/webservice/'
# params = dict(text=text)
# return await request.post(url, params, {'chr': 'utf-8'})
def join_tokens(tokens):
+43
View File
@@ -0,0 +1,43 @@
from sync.data import request
from lxml import etree
async def typograf(text, options={}):
text = text.replace('&', '&')
text = text.replace('<', '&lt;')
text = text.replace('>', '&gt;')
body = '''
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ProcessText xmlns="http://typograf.artlebedev.ru/webservices/">
<text>{text}</text>
<entityType>1</entityType>
<useBr>0</useBr>
<useP>1</useP>
<maxNobr>3</maxNobr>
</ProcessText>
</soap:Body>
</soap:Envelope>
'''.strip().format(text=text)
url = 'http://typograf.artlebedev.ru/webservices/typograf.asmx'
resp = await request.post(url, body, {}, {
'Content-Type': 'text/xml',
'SOAPAction': 'http://typograf.artlebedev.ru/webservices/ProcessText',
})
response_tree = etree.fromstring(resp.encode())
try:
# look for ProcessTextResult
typograf_response = response_tree.getchildren()[0].getchildren()[0].getchildren()[0].text
except Exception as response_tree:
print(response_tree)
return text
typograf_response = typograf_response.replace('&amp;', '&')
typograf_response = typograf_response.replace('&lt;', '<')
typograf_response = typograf_response.replace('&gt;', '>')
return typograf_response