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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.errorhandler(404)
  48. def error404(error):
  49. return render_template("error404.html"), 404
  50. if __name__ == "__main__":
  51. app.run(debug=True)