Commit ffdbfb7ef641867a846da4b923d27deebc9cffa7
1 parent
6ea2d50c
Exists in
devel
Corrige identações e endpoint de estatísticas
Showing
1 changed file
with
14 additions
and
12 deletions
Show diff stats
src/TranslationServer.py
... | ... | @@ -13,12 +13,12 @@ conn=None |
13 | 13 | app=Flask(__name__, static_url_path="", static_folder="/var/www/") |
14 | 14 | |
15 | 15 | def check_run_mode(func): |
16 | - @wraps(func) | |
17 | - def decorated_function(*args, **kwargs): | |
18 | - if RUN_MODE == "translate": | |
19 | - abort(404) | |
20 | - return func(*args, **kwargs) | |
21 | - return decorated_function | |
16 | + @wraps(func) | |
17 | + def decorated_function(*args, **kwargs): | |
18 | + if (RUN_MODE == "translate" or (RUN_MODE == "dict" and request.path == "/statistics")): | |
19 | + abort(404) | |
20 | + return func(*args, **kwargs) | |
21 | + return decorated_function | |
22 | 22 | |
23 | 23 | def dict_mode(): |
24 | 24 | global BUNDLES_PATH |
... | ... | @@ -67,9 +67,10 @@ def check_database(): |
67 | 67 | cursor.execute(create_signs_table) |
68 | 68 | cursor.execute(create_platforms_table) |
69 | 69 | cursor.execute(insert_platforms_default, ("ANDROID", 0)) |
70 | - cursor.execute(insert_platforms_default, ("IOS", 0)) | |
71 | - cursor.execute(insert_platforms_default, ("WEBGL", 0)) | |
72 | - cursor.execute(insert_platforms_default, ("STANDALONE", 0)) | |
70 | + cursor.execute(insert_platforms_default, ("IOS", 0)) | |
71 | + cursor.execute(insert_platforms_default, ("WEBGL", 0)) | |
72 | + cursor.execute(insert_platforms_default, ("STANDALONE", 0)) | |
73 | + conn.commit() | |
73 | 74 | cursor.close() |
74 | 75 | |
75 | 76 | def insert_sign_db(sign_name, value, has): |
... | ... | @@ -122,6 +123,7 @@ def translate(): |
122 | 123 | return traduzir(text) |
123 | 124 | |
124 | 125 | @app.route("/statistics") |
126 | +@check_run_mode | |
125 | 127 | def load_statistics_page(): |
126 | 128 | page_path = os.path.join(app.static_folder, "statistics") |
127 | 129 | php_output = check_output(["php", page_path]) |
... | ... | @@ -137,7 +139,7 @@ def get_sign(): |
137 | 139 | if __name__ == "__main__": |
138 | 140 | parser = argparse.ArgumentParser(description='Translation server and signs download for VLibras.') |
139 | 141 | parser.add_argument('--port', help='Port where the server will be available.', default=3000) |
140 | - parser.add_argument("--mode", help="So that the server will work.", default="translate") | |
141 | - args = parser.parse_args() | |
142 | - init_mode(args) | |
142 | + parser.add_argument("--mode", help="So that the server will work.", default="translate") | |
143 | + args = parser.parse_args() | |
144 | + init_mode(args) | |
143 | 145 | app.run(host="0.0.0.0", port=int(args.port), threaded=True, debug=False) |
144 | 146 | \ No newline at end of file | ... | ... |