diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-02-16 12:54:42 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-02-16 12:54:42 +0300 |
commit | 94463e4926519fe2edc033cefac50d6690ed9a0a (patch) | |
tree | b9d68d7353a584f48546f93603ea282be7b0ea3d /app/__init__.py | |
parent | f01e27a00b9931b28ff8184751dedbe64db79ea2 (diff) |
fixes, improvements. added text filter.
Diffstat (limited to 'app/__init__.py')
-rw-r--r-- | app/__init__.py | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/app/__init__.py b/app/__init__.py deleted file mode 100644 index 8ee21b9..0000000 --- a/app/__init__.py +++ /dev/null @@ -1,91 +0,0 @@ -import os -import time - -from . import acmespb -from flask import Flask, render_template -from flask_socketio import SocketIO, emit - -socketio = SocketIO() - - -def create_app(test_config=None): - app = Flask(__name__, instance_relative_config=True) - app.config.from_mapping( - SECRET_KEY='dev', - DATABASE=os.path.join(app.instance_path, 'app.sqlite'), - ) - - if test_config is None: - # load the instance config, if it exists, when not testing - app.config.from_pyfile('config.py', silent=True) - else: - # load the test config if passed in - app.config.from_mapping(test_config) - - # ensure the instance folder exists - try: - os.makedirs(app.instance_path) - except OSError: - pass - - socketio.init_app(app) - - @app.route('/') - def hello(): - return render_template('index.html') - - @socketio.on('get_hints') - def handle_get_hints_event(q): - print('[get_hints] id=%d, query=%s' % (q['id'], q['query'])) - if len(q['query']) < 3: - response = { - 'id': q['id'], - 'error': "query is too short" - } - emit('hints', response) - return - results = acmespb.search(q['query']) - response = { - 'id': q['id'], - 'response': results - } - emit('hints', response) - - @socketio.on('get_offers') - def handle_get_offers_event(q): - print('[get_offers] id=%d, query=%s' % (q['id'], q['query'])) - target_url, trade_names = acmespb.trade_names(q['query']) - if trade_names: - response = { - 'id': q['id'], - "response": trade_names - } - emit('hints', response) - return - - page = 1 - pages = 0 - target_url = None - while pages == 0 or page <= pages: - target_url, pages, offers = acmespb.offers(q['query'], page=page, target_url=target_url) - print("[%d] pages=%d, target_url=%s" % (page, pages, target_url)) - response = { - 'id': q['id'], - 'offers': [offer.as_dict() for offer in offers], - 'page': page, - 'pages': pages - } - emit('offers', response) - - time.sleep(0.5) - page += 1 - - response = { - 'id': q['id'], - 'end': True - } - emit('offers', response) - - # TODO empty response - - return app |