Skip to content

Instantly share code, notes, and snippets.

@derand
Created October 17, 2012 21:43
Show Gist options
  • Save derand/3908455 to your computer and use it in GitHub Desktop.
Save derand/3908455 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Andrey Derevyagin'
__copyright__ = 'Copyright © 2012, Andrey Derevyagin'
import webapp2
import random
from google.appengine.api import xmpp
import json
import time
class BakaSymbols(webapp2.RequestHandler):
def post(self):
startTime = time.time()
d = {
u'а': [u'闩', u'开'],
u'б': [u'五', ],
u'в': [u'乃', u'阝'],
u'г': [u'厂', ],
u'д': [u'凸', ],
u'е': [u'巳', u'ㅌ', ],
u'ё': [u'当', ],
u'ж': [u'水', ],
u'з': [u'弓', ],
u'и': [u'い', ],
u'й': [u'以', ],
u'к': [u'片', ],
u'л': [u'人', ],
u'м': [u'从', ],
u'н': [u'廾', u'ㅐ', ],
u'о': [u'囗', ],
u'п': [u'冂', ],
u'р': [u'尸', u'户', ],
u'с': [u'匸', ],
u'т': [u'丁', u'爪', ],
u'у': [u'丫', ],
u'ф': [u'中', ],
u'х': [u'乂', ],
u'ц': [u'니', ],
u'ч': [u'丩', ],
u'ш': [u'山', ],
u'щ': [u'屮', ],
u'ъ': [u'乙', ],
u'ы': [u'彑亅', ],
u'ь': [u'彑', ],
u'э': [u'彐', ],
u'ю': [u'ㅏ口', ],
u'я': [u'牙', ],
u'.': [u'。', ],
u',': [u'、', ],
u' ': [u' ', ],
u'-': [u'ー', ],
}
str = self.request.get('str')
out = map(lambda x: d.has_key(x.lower()) and random.choice(d[x.lower()]) or x, str)
self.response.headers["Content-Type"] = 'application/json'
self.response.out.write(json.dumps({'status': 'ok', 'source': str, 'string': ''.join(out)}))
xmpp.send_message('<JID>', '%f: %s'%(time.time()-startTime, str))
app = webapp2.WSGIApplication([
('/api/baka_symbols', BakaSymbols)
], debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment