A semantic search engine for source code https://bitshift.benkurtovic.com/
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

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