Commit cc482bb529aaf41093a63da16e5ec69c05aa3f4c

Authored by Erickson Silva
1 parent fac9f334
Exists in devel

Adiciona endpoint '/statistics'

Showing 1 changed file with 9 additions and 2 deletions   Show diff stats
src/TranslationServer.py
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 from flask import Flask, request, send_file, abort 4 from flask import Flask, request, send_file, abort
5 from functools import wraps 5 from functools import wraps
6 from PortGlosa import traduzir 6 from PortGlosa import traduzir
  7 +from subprocess import check_output
7 import os, argparse 8 import os, argparse
8 9
9 RUN_MODE=None 10 RUN_MODE=None
@@ -47,7 +48,7 @@ def init_mode(args): @@ -47,7 +48,7 @@ def init_mode(args):
47 print "# Server started in dictionary mode. Requests will be accepted for translation of texts and download bundles.\n# Endpoints '/translate' and '/sign' are available." 48 print "# Server started in dictionary mode. Requests will be accepted for translation of texts and download bundles.\n# Endpoints '/translate' and '/sign' are available."
48 elif RUN_MODE == "full": 49 elif RUN_MODE == "full":
49 full_mode() 50 full_mode()
50 - print "# Server started in full mode. Requests will be accepted for translation of texts, download bundles. All bundles requests will be stored in a database.\n# Endpoints '/translate', '/sign' are available." 51 + print "# Server started in full mode. Requests will be accepted for translation of texts, download bundles. All bundles requests will be stored in a database.\n# Endpoints '/translate', '/sign' and '/statistics' are available."
51 elif RUN_MODE == "translate": 52 elif RUN_MODE == "translate":
52 print "# Server started in translation mode.\n# Only endpoint '/translate' available." 53 print "# Server started in translation mode.\n# Only endpoint '/translate' available."
53 54
@@ -106,6 +107,12 @@ def translate(): @@ -106,6 +107,12 @@ def translate():
106 text = request.args.get('text').encode("UTF-8") 107 text = request.args.get('text').encode("UTF-8")
107 return traduzir(text) 108 return traduzir(text)
108 109
  110 +@app.route("/statistics")
  111 +def load_statistics_page():
  112 + page_path = os.path.join(app.static_folder, "statistics")
  113 + php_output = check_output(["php", page_path])
  114 + return php_output
  115 +
109 @app.route("/sign", methods=['GET']) 116 @app.route("/sign", methods=['GET'])
110 @check_run_mode 117 @check_run_mode
111 def get_sign(): 118 def get_sign():
@@ -120,4 +127,4 @@ if __name__ == "__main__": @@ -120,4 +127,4 @@ if __name__ == "__main__":
120 parser.add_argument("--mode", help="Video title", default="translate") 127 parser.add_argument("--mode", help="Video title", default="translate")
121 args = parser.parse_args() 128 args = parser.parse_args()
122 init_mode(args) 129 init_mode(args)
123 - app.run(host="0.0.0.0", port=int(args.port), threaded=True, debug=False)  
124 \ No newline at end of file 130 \ No newline at end of file
  131 + app.run(host="0.0.0.0", port=int(args.port), threaded=True, debug=False)