rest_api.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from os import environ
  2. from flask import Flask, request
  3. def create_app():
  4. app = Flask(__name__)
  5. app.config.update({
  6. "ENV": environ.get("TXL_APP_MODE", "production"),
  7. "SECRET_KEY": environ["TXL_FLASK_SECRET"],
  8. "USE_X_SENDFILE": True,
  9. "JSON_AS_ASCII": False,
  10. "JSONIFY_PRETTYPRINT_REGULAR": True,
  11. })
  12. return app
  13. app = create_app()
  14. @app.route("/health", methods=["GET"])
  15. def health_check():
  16. return "I'm alive!\n"
  17. @app.route("/languages", methods=["GET"])
  18. def list_languages():
  19. return "TODO list of supported languages goes here."
  20. @app.route("/scripts")
  21. @app.route("/scripts/<lang>")
  22. def list_scripts(lang=None):
  23. lang_str = f"for {lang}" if lang else "for all languages"
  24. return f"TODO list of supported scripts {lang_str} go here."
  25. @app.route("/trans/<script>/<lang>/<dir>", methods=["POST"])
  26. def transliterate(script, lang, dir):
  27. in_txt = request.form["text"]
  28. return (
  29. f"TODO transliterate text {in_txt}, language {lang}, "
  30. f"script {script}, direction {dir}")