Skip to content

Commit

Permalink
Добавлено простое WSGI (Bottle)
Browse files Browse the repository at this point in the history
  • Loading branch information
jar3b committed Feb 1, 2016
1 parent 63f7827 commit e249be2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
2 changes: 0 additions & 2 deletions aore/__init__.py
@@ -1,9 +1,7 @@
import logging
import os
import sys

reload(sys)
cwd = os.getcwd()
sys.path.append(cwd)
sys.setdefaultencoding("utf-8")
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
4 changes: 2 additions & 2 deletions aore/fias/search.py
Expand Up @@ -14,15 +14,15 @@ class SphinxSearch:
def __init__(self, db):
self.delta_len = 2

self.rating_limit_soft = 0.4
self.rating_limit_soft = 0.6
self.rating_limit_soft_count = 6
self.word_length_soft = 3

self.rating_limit_hard = 0.82
self.rating_limit_hard_count = 3

self.default_rating_delta = 2
self.regression_coef = 0.04
self.regression_coef = 0.01

self.db = db
self.client_sugg = sphinxapi.SphinxClient()
Expand Down
33 changes: 33 additions & 0 deletions aore/phias.py
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
import json
import logging

from bottle import Bottle

from aore.fias.fiasfactory import FiasFactory

logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
app = Bottle()
fias_factory = FiasFactory()


@app.route('/expand/<aoid:re:[\w]{8}(-[\w]{4}){3}-[\w]{12}>')
def expand(aoid):
return json.dumps(fias_factory.expand(aoid))


@app.route('/normalize/<aoid:re:[\w]{8}(-[\w]{4}){3}-[\w]{12}>')
def normalize(aoid):
return json.dumps(fias_factory.normalize(aoid))


@app.route('/find/<text>')
@app.route('/find/<text>/<strong>')
def find(text, strong=False):
strong = (strong == "strong")
return json.dumps(fias_factory.find(text, strong))


@app.error(404)
def error404(error):
return json.dumps(dict(error="Page not found"))
13 changes: 3 additions & 10 deletions manage.py
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
import json
import logging
import optparse

from aore.fias.fiasfactory import FiasFactory
from aore.miscutils.sphinx import SphinxHelper
from aore.updater.soapreceiver import SoapReceiver
from aore.updater.updater import Updater

logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)


def print_fias_versions():
imp = SoapReceiver()
Expand Down Expand Up @@ -86,8 +89,6 @@ def main():
help="Path to Sphinx indexer binary. Required for '--sphinx-configure'")
p.add_option('--output-conf', '-o',
help="Output config filename. Required for '--sphinx-configure'")
p.add_option('--test', '-t', action="store_true", dest="test",
help="Test")

options, arguments = p.parse_args()

Expand Down Expand Up @@ -116,13 +117,5 @@ def main():
sphinxh = SphinxHelper()
sphinxh.configure_indexer(options.indexer_path, options.output_conf)

# 4 Debug purposes..
if options.test:
sph = FiasFactory()
print json.dumps(sph.normalize("463ce8e4-928b-45cc-be76-46c2494632b6"))
print json.dumps(sph.expand("463ce8e4-928b-45cc-be76-46c2494632b6"))
print json.dumps(sph.find('ул кемровая пасраул алтай майминский р-н'))


if __name__ == '__main__':
main()
15 changes: 4 additions & 11 deletions passenger_wsgi.py
@@ -1,15 +1,8 @@
# -*- coding: utf-8 -*-

import os
import sys
from aore import phias

# append current dir to module path
reload(sys)
cwd = os.path.dirname(os.path.abspath(__file__))
sys.path.append(cwd)
sys.setdefaultencoding("utf-8")
# sys.path.append('/home/i/interc7j/.local/lib/python2.7/site-packages')
application = phias.app

from aore import aore

application = aore.app
if __name__ == '__main__':
application.run(host='localhost', port=55001, debug=True)

0 comments on commit e249be2

Please sign in to comment.