A semantic search engine for source code https://bitshift.benkurtovic.com/
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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