A semantic search engine for source code https://bitshift.benkurtovic.com/
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

59 строки
1.5 KiB

  1. """
  2. Module to contain all the project's Flask server plumbing.
  3. """
  4. from json import dumps
  5. from flask import Flask, make_response, render_template, request
  6. from bitshift import assets
  7. from bitshift.database import Database
  8. from bitshift.languages import LANGS
  9. from bitshift.query import parse_query, QueryParseException
  10. app = Flask(__name__)
  11. app.config.from_object("bitshift.config")
  12. app_env = app.jinja_env
  13. app_env.line_statement_prefix = "="
  14. app_env.globals.update(assets=assets)
  15. database = Database()
  16. @app.route("/")
  17. def index():
  18. return render_template("index.html", typeahead_languages=LANGS)
  19. @app.route("/search.json")
  20. def search():
  21. def reply(json):
  22. resp = make_response(dumps(json))
  23. resp.mimetype = "application/json"
  24. return resp
  25. query, page = request.args.get("q"), request.args.get("p", 1)
  26. if not query:
  27. return reply({"error": "No query given"})
  28. try:
  29. tree = parse_query(query)
  30. except QueryParseException as exc:
  31. return reply({"error": exc.args[0]})
  32. try:
  33. page = int(page)
  34. except ValueError:
  35. return reply({"error": u"Invalid page number: %s" % page})
  36. count, codelets = database.search(tree, page)
  37. results = [clt.serialize() for clt in codelets]
  38. return reply({"count": count, "results": results})
  39. @app.route("/about")
  40. def about():
  41. return render_template("about.html")
  42. @app.route("/developers")
  43. def developers():
  44. return render_template("developers.html")
  45. if __name__ == "__main__":
  46. app.run(debug=True)