You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
54 lines
1.4 KiB
import falcon
|
|
import json
|
|
import os
|
|
from libindic.payyans import Payyans
|
|
instance = Payyans()
|
|
|
|
all_fonts = [
|
|
'ambili',
|
|
'charaka',
|
|
'haritha',
|
|
'indulekha',
|
|
'karthika',
|
|
'manorama',
|
|
'matweb',
|
|
'nandini',
|
|
'panchari',
|
|
'revathi',
|
|
'template',
|
|
'uma',
|
|
]
|
|
|
|
def convert(txt, font):
|
|
# txt = txt.replace("ൺ", "ണ്") \
|
|
# .replace("ൻ", "ന്") \
|
|
# .replace("ർ", "ര്") \
|
|
# .replace("ൽ", "ല്") \
|
|
# .replace("ൾ", "ള്") \
|
|
# .replace("ോ", "ോ") \
|
|
# .replace("ൊ", "ൊ")
|
|
|
|
return instance.Unicode2ASCII(txt, font)
|
|
|
|
class QResource:
|
|
def on_post(self, req, resp):
|
|
body = req.get_media()
|
|
text = body.get( 'text' )
|
|
font_name = body.get( 'font' )
|
|
if( font_name not in all_fonts ):
|
|
raise falcon.HTTPBadRequest('Invalid font')
|
|
resp.set_header('content-type', 'application/json; charset=UTF-8')
|
|
data = { }
|
|
data['ascii'] = convert(text, font_name )
|
|
resp.body = json.dumps( data, default=str )
|
|
|
|
|
|
class RedirectingResource:
|
|
def on_get(self, req, resp):
|
|
raise falcon.HTTPMovedPermanently('/index.html')
|
|
|
|
api = falcon.API()
|
|
api.add_route('/', RedirectingResource())
|
|
api.add_static_route('/', os.path.dirname(os.path.realpath(__file__)) + '/static' )
|
|
api.add_route('/api/a2u', QResource())
|
|
|
|
|