mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-07 08:03:15 +00:00
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
import requests
|
|
|
|
class TypographError(Exception):
|
|
pass
|
|
|
|
|
|
def typograph(text):
|
|
text = text.replace('&', '&')
|
|
text = text.replace('<', '<')
|
|
text = text.replace('>', '>')
|
|
template = f'''<?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>3</entityType>
|
|
<useBr>0</useBr>
|
|
<useP>0</useP>
|
|
<maxNobr>0</maxNobr>
|
|
</ProcessText>
|
|
</soap:Body>
|
|
</soap:Envelope>
|
|
'''
|
|
result = requests.post(
|
|
url='http://typograf.artlebedev.ru/webservices/typograf.asmx',
|
|
data=template.encode('utf-8'),
|
|
headers={
|
|
'Content-Type': 'text/xml',
|
|
'SOAPAction': 'http://typograf.artlebedev.ru/webservices/ProcessText'
|
|
}
|
|
)
|
|
if result.ok and 'ProcessTextResult' in result.text:
|
|
result_text = result.text.split('<ProcessTextResult>')[1].split('</ProcessTextResult>')[0].rstrip()
|
|
result_text = result_text.replace('&', '&')
|
|
result_text = result_text.replace('<', '<')
|
|
result_text = result_text.replace('>', '>')
|
|
return result_text
|
|
else:
|
|
raise TypographError(result.text)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import sys
|
|
print((typograph(sys.stdin.read())))
|