[Sync] Kazimir uses ALS Typograf
This commit is contained in:
1 parent
3ecf1deb5d
commit
a034254cbe
2 files changed
+48
-3
No files matched your search
@@ -94,9 +94,11 @@ def html_from_tree(tree):
|
|||||||
|
|
||||||
|
|
||||||
async def typo(text):
|
async def typo(text):
|
||||||
url = 'http://www.typograf.ru/webservice/'
|
from kazimir import artlebedev
|
||||||
params = dict(text=text)
|
return await artlebedev.typograf(text)
|
||||||
return await request.post(url, params, {'chr': 'utf-8'})
|
# url = 'http://www.typograf.ru/webservice/'
|
||||||
|
# params = dict(text=text)
|
||||||
|
# return await request.post(url, params, {'chr': 'utf-8'})
|
||||||
|
|
||||||
|
|
||||||
def join_tokens(tokens):
|
def join_tokens(tokens):
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
from sync.data import request
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
|
|
||||||
|
async def typograf(text, options={}):
|
||||||
|
text = text.replace('&', '&')
|
||||||
|
text = text.replace('<', '<')
|
||||||
|
text = text.replace('>', '>')
|
||||||
|
|
||||||
|
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('&', '&')
|
||||||
|
typograf_response = typograf_response.replace('<', '<')
|
||||||
|
typograf_response = typograf_response.replace('>', '>')
|
||||||
|
return typograf_response
|
||||||
Reference in new issue
Block a user