diff options
author | neodarz <neodarz@neodarz.net> | 2019-01-20 00:24:49 +0100 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-01-20 00:32:27 +0100 |
commit | 5ffbc1172738e8ee26c934f4a82d2d3bbc3a5b37 (patch) | |
tree | eca96ba661d1b6bf934abdf3bb0db23da6c7392f /app.py | |
parent | aeaf4cb8cdd6d413cbd9e9d3c1156bd23bd0b386 (diff) | |
download | khanindexer-5ffbc1172738e8ee26c934f4a82d2d3bbc3a5b37.tar.xz khanindexer-5ffbc1172738e8ee26c934f4a82d2d3bbc3a5b37.zip |
Use Manticorsearch JSON API instead of custom search API
The migration is due to the fact that python use far more ressources
that a simple JSON POST request directly on the Manticorsearch server.
Diffstat (limited to 'app.py')
-rw-r--r-- | app.py | 44 |
1 files changed, 2 insertions, 42 deletions
@@ -3,34 +3,10 @@ import sys from scrapy.crawler import CrawlerProcess from scrapy import spiderloader from scrapy.utils.project import get_project_settings -from flask import Flask, request, jsonify -import json - -from sphinx import sphinx from database.models import Page, db -import config - -app = Flask(__name__) - -@app.route("/", methods=['GET', 'POST']) -def search(): - query = request.args.get('search') - index = request.args.get('index') - if query != '' and query != None and index != '' and index != None: - response = sphinx.search(query, index) - elif query is None: - response = {'error': 1, 'msg': 'Use `search` attribute for make a search'} - elif index == None: - response = {'error': 1, 'msg': 'Use `index` attribute to precise an index'} - elif index == '': - response = {'error': 1, 'msg': '`index` cannot be null'} - else: - response = {'error': 1, 'msg': '`search` cannot be null'} - return jsonify(response) - -def crawl(): +def main(): try: db.create_tables(Page.__subclasses__()) settings = get_project_settings() @@ -42,21 +18,5 @@ def crawl(): except Exception as e: print(e) -def main(): - - app.run(debug=True, use_reloader=True) - -def show_help(): - print("Launch server => "+str(sys.argv[0])) - print("Launch all crawler => "+str(sys.argv[0])+" crawl") - if __name__ == '__main__': - if len(sys.argv) == 1: - main() - elif len(sys.argv) == 2: - if sys.argv[1] == "crawl": - crawl() - else: - show_help() - else: - show_help() + main() |