Commit 49c9936f15801ec4dd0fbe1864bed33856546fb6
Exists in
master
and in
1 other branch
Merge remote-tracking branch 'origin/dynamic'
Conflicts: .gitignore
Showing
9 changed files
with
123 additions
and
61 deletions
Show diff stats
.gitignore
| 1 | +.* | ||
| 2 | +!*.gitignore | ||
| 3 | +!*.gitempty | ||
| 4 | +*~ | ||
| 5 | +*.log | ||
| 6 | +*.pyc | ||
| 7 | +corretor.conf | ||
| 8 | +corretor.wsgi | ||
| 9 | +settings_local.py | ||
| 10 | +env/ | ||
| 11 | +videos/ | ||
| 12 | +tmp/ | ||
| 13 | +uploads/ | ||
| 14 | + | ||
| 1 | *.egg-info | 15 | *.egg-info |
| 2 | *.tox | 16 | *.tox |
| 3 | .*.swp | 17 | .*.swp |
| 4 | -env/ | ||
| 5 | -events.log | ||
| 6 | -*.pyc | ||
| 7 | *.db | 18 | *.db |
| 8 | settings_local.py | 19 | settings_local.py |
| 9 | -env/ | ||
| 10 | doc/_build | 20 | doc/_build |
| 11 | *.un~ | 21 | *.un~ |
| 12 | *.wsgi | 22 | *.wsgi |
requirements.txt
settings_local.py
| 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
| 2 | -# Corretor Server Configuration | ||
| 3 | -SERVER_HOST = "0.0.0.0" | 2 | +# WikiLibras Server Configuration |
| 3 | +SERVER_HOST = "150.165.204.35" | ||
| 4 | SERVER_PORT = 8003 | 4 | SERVER_PORT = 8003 |
| 5 | AGREEMENT_NUMBER = 2 | 5 | AGREEMENT_NUMBER = 2 |
| 6 | -API_HOST = "http://0.0.0.0:5001" | 6 | +API_HOST = "http://150.165.204.35:201" |
| 7 | +API_DB_HOST = "http://150.165.204.35:200" | ||
| 8 | +UPLOAD_SIGN_HOST = "http://150.165.204.35:200/addsinal" | ||
| 9 | +HOMEPAGE_URL = "http://wikilibras.lavid.ufpb.br" | ||
| 7 | 10 | ||
| 8 | # Apache Configuration | 11 | # Apache Configuration |
| 9 | -APACHE_HOST = False | 12 | +APACHE_HOST = True |
| 10 | APACHE_HOST_ENDPOINT = "/wikilibras-backend" | 13 | APACHE_HOST_ENDPOINT = "/wikilibras-backend" |
| 11 | APACHE_STATIC_FILES_ENDPOINT = "/wikilibras" | 14 | APACHE_STATIC_FILES_ENDPOINT = "/wikilibras" |
| 12 | 15 | ||
| 13 | # PyBossa Configuration | 16 | # PyBossa Configuration |
| 14 | PYBOSSA_APP_NAME = "WikiLibras" | 17 | PYBOSSA_APP_NAME = "WikiLibras" |
| 15 | -PYBOSSA_APP_SHORT_NAME = "wikilibras" | 18 | +PYBOSSA_APP_SHORT_NAME = "wikilibras" |
| 16 | PYBOSSA_APP_DESCRIPTION = "Esse projeto possibilitará que voluntários contribuam na expansão de um dicionário de LIBRAS." | 19 | PYBOSSA_APP_DESCRIPTION = "Esse projeto possibilitará que voluntários contribuam na expansão de um dicionário de LIBRAS." |
| 17 | -PYBOSSA_ENDPOINT = "http://0.0.0.0:5000" | ||
| 18 | -#PYBOSSA_API_KEY = "263302c0-07eb-44e4-956c-9b34cc301553" | ||
| 19 | -PYBOSSA_API_KEY = "ed85ccd7-1417-4886-88bb-2e760509cef2" | 20 | +PYBOSSA_ENDPOINT = "http://150.165.204.35/pybossa" |
| 21 | +PYBOSSA_API_KEY = "0176e74e-4f70-45ef-bc75-6c6ebae8d170" |
settings_local.py.tmpl
| @@ -16,5 +16,5 @@ APACHE_STATIC_FILES_ENDPOINT = "/wikilibras" | @@ -16,5 +16,5 @@ APACHE_STATIC_FILES_ENDPOINT = "/wikilibras" | ||
| 16 | PYBOSSA_APP_NAME = "WikiLibras" | 16 | PYBOSSA_APP_NAME = "WikiLibras" |
| 17 | PYBOSSA_APP_SHORT_NAME = "wikilibras" | 17 | PYBOSSA_APP_SHORT_NAME = "wikilibras" |
| 18 | PYBOSSA_APP_DESCRIPTION = "Esse projeto possibilitará que voluntários contribuam na expansão de um dicionário de LIBRAS." | 18 | PYBOSSA_APP_DESCRIPTION = "Esse projeto possibilitará que voluntários contribuam na expansão de um dicionário de LIBRAS." |
| 19 | -PYBOSSA_ENDPOINT = "http://localhost:5000" | 19 | +PYBOSSA_ENDPOINT = "http://localhost:201" |
| 20 | PYBOSSA_API_KEY = "my-api-key" | 20 | PYBOSSA_API_KEY = "my-api-key" |
| 21 | \ No newline at end of file | 21 | \ No newline at end of file |
view/assets/css/main.css
| @@ -500,7 +500,8 @@ ul.rig.columns-4 li { | @@ -500,7 +500,8 @@ ul.rig.columns-4 li { | ||
| 500 | 500 | ||
| 501 | #approval-msg { | 501 | #approval-msg { |
| 502 | display: none; | 502 | display: none; |
| 503 | - margin: 0px; | 503 | + margin: 0px; |
| 504 | + padding-left: 14px; | ||
| 504 | } | 505 | } |
| 505 | 506 | ||
| 506 | /* Thanks Screen */ | 507 | /* Thanks Screen */ |
| @@ -519,4 +520,4 @@ ul.rig.columns-4 li { | @@ -519,4 +520,4 @@ ul.rig.columns-4 li { | ||
| 519 | 520 | ||
| 520 | #completed-all-task-msg { | 521 | #completed-all-task-msg { |
| 521 | display: none; | 522 | display: none; |
| 522 | -} | ||
| 523 | \ No newline at end of file | 523 | \ No newline at end of file |
| 524 | +} |
view/assets/js/wikilibras.js
| @@ -324,22 +324,50 @@ | @@ -324,22 +324,50 @@ | ||
| 324 | _getRenderedAvatarUrl(userId, signName)); | 324 | _getRenderedAvatarUrl(userId, signName)); |
| 325 | $("#render-avatar").fadeIn(300); | 325 | $("#render-avatar").fadeIn(300); |
| 326 | } | 326 | } |
| 327 | + | ||
| 328 | + function _showInitialScreen(toShow) { | ||
| 329 | + if (toShow) { | ||
| 330 | + $("#initial-screen").fadeIn(300); | ||
| 331 | + $("#initial-screen video").get(0).play(); | ||
| 332 | + } else { | ||
| 333 | + $("#initial-screen").hide(); | ||
| 334 | + $("#initial-screen video").get(0).pause(); | ||
| 335 | + } | ||
| 336 | + } | ||
| 337 | + | ||
| 338 | + function _showConfigurationScreen(toShow) { | ||
| 339 | + if (toShow) { | ||
| 340 | + $("#configuration-screen").show(); | ||
| 341 | + $("#ref-video-container video").get(0).play(); | ||
| 342 | + } else { | ||
| 343 | + $("#configuration-screen").hide(); | ||
| 344 | + $("#ref-video-container video").get(0).pause(); | ||
| 345 | + } | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + function _showRenderScreen(toShow) { | ||
| 349 | + if (toShow) { | ||
| 350 | + $("#render-screen").fadeIn(300); | ||
| 351 | + $("#render-ref video").get(0).play(); | ||
| 352 | + $("#render-avatar video").get(0).play(); | ||
| 353 | + } else { | ||
| 354 | + $("#render-screen").hide(); | ||
| 355 | + $("#render-ref video").get(0).pause(); | ||
| 356 | + $("#render-avatar video").get(0).pause(); | ||
| 357 | + } | ||
| 358 | + } | ||
| 327 | 359 | ||
| 328 | function _setupRenderScreen() { | 360 | function _setupRenderScreen() { |
| 329 | - $("#configuration-screen").hide(); | 361 | + _showConfigurationScreen(false); |
| 362 | + _showRenderScreen(true); | ||
| 330 | $("#render-avatar").hide(); | 363 | $("#render-avatar").hide(); |
| 331 | - $("#render-screen").show(); | ||
| 332 | $("#render-loading").fadeIn(300); | 364 | $("#render-loading").fadeIn(300); |
| 333 | - $("#render-ref video").prop("controls", false); | ||
| 334 | - $("#render-ref video").get(0).pause(); | ||
| 335 | $("#render-button-container .btn").hide(); | 365 | $("#render-button-container .btn").hide(); |
| 336 | $("#finish-button").addClass("disabled"); | 366 | $("#finish-button").addClass("disabled"); |
| 337 | $("#finish-button").show(); | 367 | $("#finish-button").show(); |
| 338 | 368 | ||
| 339 | _submitParameterJSON(function() { | 369 | _submitParameterJSON(function() { |
| 340 | $("#render-loading").fadeOut(300); | 370 | $("#render-loading").fadeOut(300); |
| 341 | - $("#render-ref video").prop("controls", true); | ||
| 342 | - $("#render-ref video").get(0).play(); | ||
| 343 | $("#finish-button").removeClass("disabled"); | 371 | $("#finish-button").removeClass("disabled"); |
| 344 | _showRenderedAvatar(parsedParameterJSON); | 372 | _showRenderedAvatar(parsedParameterJSON); |
| 345 | }); | 373 | }); |
| @@ -349,10 +377,9 @@ | @@ -349,10 +377,9 @@ | ||
| 349 | $("#render-button-container .btn").hide(); | 377 | $("#render-button-container .btn").hide(); |
| 350 | $("#approval-button").show(); | 378 | $("#approval-button").show(); |
| 351 | $("#approval-msg").show(); | 379 | $("#approval-msg").show(); |
| 352 | - $("#render-ref video").get(0).play(); | ||
| 353 | 380 | ||
| 354 | _showRenderedAvatar(parameterJSON); | 381 | _showRenderedAvatar(parameterJSON); |
| 355 | - $("#render-screen").fadeIn(300); | 382 | + _showRenderScreen(true); |
| 356 | } | 383 | } |
| 357 | 384 | ||
| 358 | function _submitAnswer(task, deferred, status) { | 385 | function _submitAnswer(task, deferred, status) { |
| @@ -362,7 +389,7 @@ | @@ -362,7 +389,7 @@ | ||
| 362 | } else { | 389 | } else { |
| 363 | _saveAnswer(task, deferred, answer); | 390 | _saveAnswer(task, deferred, answer); |
| 364 | } | 391 | } |
| 365 | - $("#render-screen").hide(); | 392 | + _showRenderScreen(false); |
| 366 | $("#thanks-screen").show(); | 393 | $("#thanks-screen").show(); |
| 367 | } | 394 | } |
| 368 | 395 | ||
| @@ -383,12 +410,12 @@ | @@ -383,12 +410,12 @@ | ||
| 383 | if (hasLastAnswer) { | 410 | if (hasLastAnswer) { |
| 384 | _setupApprovalScreen(last_answer.parameter_json); | 411 | _setupApprovalScreen(last_answer.parameter_json); |
| 385 | } else { | 412 | } else { |
| 386 | - $("#initial-screen").fadeIn(300); | 413 | + _showInitialScreen(true); |
| 387 | } | 414 | } |
| 388 | 415 | ||
| 389 | $("#start-button").off("click").on("click", function() { | 416 | $("#start-button").off("click").on("click", function() { |
| 390 | - $("#initial-screen").hide(); | ||
| 391 | - $("#configuration-screen").show(); | 417 | + _showInitialScreen(false); |
| 418 | + _showConfigurationScreen(true); | ||
| 392 | }); | 419 | }); |
| 393 | $("#ready-button").off("click").on("click", function() { | 420 | $("#ready-button").off("click").on("click", function() { |
| 394 | if ($(this).hasClass('disabled')) { | 421 | if ($(this).hasClass('disabled')) { |
| @@ -398,8 +425,8 @@ | @@ -398,8 +425,8 @@ | ||
| 398 | _setupRenderScreen(); | 425 | _setupRenderScreen(); |
| 399 | }); | 426 | }); |
| 400 | $("#render-edit").off("click").on("click", function() { | 427 | $("#render-edit").off("click").on("click", function() { |
| 401 | - $("#render-screen").hide(); | ||
| 402 | - $("#configuration-screen").show(); | 428 | + _showRenderScreen(false); |
| 429 | + _showConfigurationScreen(true); | ||
| 403 | }); | 430 | }); |
| 404 | $("#finish-button").off("click").on("click", function() { | 431 | $("#finish-button").off("click").on("click", function() { |
| 405 | if ($(this).hasClass('disabled')) { | 432 | if ($(this).hasClass('disabled')) { |
view/template.html
| @@ -63,7 +63,7 @@ | @@ -63,7 +63,7 @@ | ||
| 63 | <div id="ref-video-panel" class="col-sm-12"> | 63 | <div id="ref-video-panel" class="col-sm-12"> |
| 64 | <div id="ref-video-container" class="col-sm-10"> | 64 | <div id="ref-video-container" class="col-sm-10"> |
| 65 | <video src="" preload="metadata" | 65 | <video src="" preload="metadata" |
| 66 | - class="ref-video video-body-main video-border" autoplay loop | 66 | + class="ref-video video-body-main video-border" loop |
| 67 | controls> | 67 | controls> |
| 68 | <source type="video/webm"> | 68 | <source type="video/webm"> |
| 69 | </video> | 69 | </video> |
| @@ -298,11 +298,11 @@ | @@ -298,11 +298,11 @@ | ||
| 298 | </div> | 298 | </div> |
| 299 | <div id="teached-signs-container" class="sub-main-container"> | 299 | <div id="teached-signs-container" class="sub-main-container"> |
| 300 | <h4 class="teached-signs-msg" type="none">Você ainda não ensinou | 300 | <h4 class="teached-signs-msg" type="none">Você ainda não ensinou |
| 301 | - sinais a Ícaro.</h4> | ||
| 302 | - <h4 class="teached-signs-msg" type="one">Você já ensinou a Ícaro | 301 | + sinais ao Ícaro.</h4> |
| 302 | + <h4 class="teached-signs-msg" type="one">Você já ensinou ao Ícaro | ||
| 303 | 1 sinal de LIBRAS.</h4> | 303 | 1 sinal de LIBRAS.</h4> |
| 304 | <h4 class="teached-signs-msg" type="more"> | 304 | <h4 class="teached-signs-msg" type="more"> |
| 305 | - Você já ensinou a Ícaro <span>x</span> sinais de LIBRAS. | 305 | + Você já ensinou ao Ícaro <span>x</span> sinais de LIBRAS. |
| 306 | </h4> | 306 | </h4> |
| 307 | <div id="signs-list-container" class="row"></div> | 307 | <div id="signs-list-container" class="row"></div> |
| 308 | <div id="teached-sign-modal" class="modal fade" tabindex="-1" | 308 | <div id="teached-sign-modal" class="modal fade" tabindex="-1" |
| @@ -318,11 +318,11 @@ | @@ -318,11 +318,11 @@ | ||
| 318 | </div> | 318 | </div> |
| 319 | </div> | 319 | </div> |
| 320 | <div id="tutorial-container" class="sub-main-container"> | 320 | <div id="tutorial-container" class="sub-main-container"> |
| 321 | - <h4>Aprenda como ensinar uma expressão a Ícaro.</h4> | 321 | + <h4>Aprenda como ensinar o Ícaro uma expressão.</h4> |
| 322 | <iframe width="560" height="315" | 322 | <iframe width="560" height="315" |
| 323 | src="http://www.youtube.com/embed/AFRxTpNJc4I?controls=2&showinfo=0"> | 323 | src="http://www.youtube.com/embed/AFRxTpNJc4I?controls=2&showinfo=0"> |
| 324 | </iframe> | 324 | </iframe> |
| 325 | - <h4>Aprenda como ensinar uma configuração de mão a Ícaro.</h4> | 325 | + <h4>Aprenda como ensinar o Ícaro uma configuração de mão.</h4> |
| 326 | <iframe width="560" height="315" | 326 | <iframe width="560" height="315" |
| 327 | src="http://www.youtube.com/embed/JJV2DX8s1rg?controls=2&showinfo=0"> | 327 | src="http://www.youtube.com/embed/JJV2DX8s1rg?controls=2&showinfo=0"> |
| 328 | </iframe> | 328 | </iframe> |
| @@ -351,4 +351,4 @@ | @@ -351,4 +351,4 @@ | ||
| 351 | <script type="text/javascript"> | 351 | <script type="text/javascript"> |
| 352 | wikilibras.run("{{ server }}", "{{ server_backend }}", | 352 | wikilibras.run("{{ server }}", "{{ server_backend }}", |
| 353 | "{{ app_shortname }}", "{{ api_host }}", "{{ upload_sign_host }}"); | 353 | "{{ app_shortname }}", "{{ api_host }}", "{{ upload_sign_host }}"); |
| 354 | -</script> | ||
| 355 | \ No newline at end of file | 354 | \ No newline at end of file |
| 355 | +</script> |
view/videos/CALAR_REF.webm
No preview for this file type
wikilibras.py
| @@ -4,42 +4,37 @@ from werkzeug import secure_filename | @@ -4,42 +4,37 @@ from werkzeug import secure_filename | ||
| 4 | import pbclient | 4 | import pbclient |
| 5 | import os | 5 | import os |
| 6 | import pyutil | 6 | import pyutil |
| 7 | +import requests | ||
| 8 | +import tempfile | ||
| 9 | +import shutil | ||
| 7 | 10 | ||
| 8 | class Wikilibras: | 11 | class Wikilibras: |
| 9 | - | 12 | + |
| 10 | def __init__(self, configuration, template_env): | 13 | def __init__(self, configuration, template_env): |
| 11 | self.config = configuration | 14 | self.config = configuration |
| 12 | self.env = template_env | 15 | self.env = template_env |
| 13 | self.__setup_pb_client() | 16 | self.__setup_pb_client() |
| 14 | - | 17 | + |
| 15 | def __setup_pb_client(self): | 18 | def __setup_pb_client(self): |
| 16 | - pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) | 19 | + pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) |
| 17 | pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) | 20 | pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) |
| 18 | - | 21 | + |
| 19 | def __find_project(self, app_short_name): | 22 | def __find_project(self, app_short_name): |
| 20 | projects = pbclient.find_project(short_name=app_short_name) | 23 | projects = pbclient.find_project(short_name=app_short_name) |
| 21 | return projects[0] if len(projects) > 0 else None | 24 | return projects[0] if len(projects) > 0 else None |
| 22 | - | 25 | + |
| 23 | def __setup_project(self, project): | 26 | def __setup_project(self, project): |
| 24 | - self.__create_tasks(project) | ||
| 25 | self.__update_project_info(project) | 27 | self.__update_project_info(project) |
| 26 | - | ||
| 27 | - def __create_tasks(self, project): | ||
| 28 | - test_signs = ["CALAR", "ENSINADO", "ENTANTO", "ENTENDIDO"] | ||
| 29 | - #test_signs = ["CALAR"] | ||
| 30 | - for sign in test_signs: | ||
| 31 | - task = dict(sign_name=sign, submission_date=pyutil.get_date_now()) | ||
| 32 | - pbclient.create_task(project.id, task) | ||
| 33 | - | 28 | + |
| 34 | def __update_project_info(self, project): | 29 | def __update_project_info(self, project): |
| 35 | template = self.env.get_template('template.html') | 30 | template = self.env.get_template('template.html') |
| 36 | project.info['task_presenter'] = template.render(server=self.config['HOST_STATIC_FILES_ENDPOINT'], server_backend=self.config['HOST_ENDPOINT'], app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'], api_host=self.config['API_HOST'], homepage_url=self.config['HOMEPAGE_URL'], upload_sign_host=self.config['UPLOAD_SIGN_HOST']) | 31 | project.info['task_presenter'] = template.render(server=self.config['HOST_STATIC_FILES_ENDPOINT'], server_backend=self.config['HOST_ENDPOINT'], app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'], api_host=self.config['API_HOST'], homepage_url=self.config['HOMEPAGE_URL'], upload_sign_host=self.config['UPLOAD_SIGN_HOST']) |
| 37 | project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" | 32 | project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" |
| 38 | project.info['sched'] = "incremental" | 33 | project.info['sched'] = "incremental" |
| 34 | + project.info['published'] = True | ||
| 39 | project.allow_anonymous_contributors = False | 35 | project.allow_anonymous_contributors = False |
| 40 | - project.published = True | ||
| 41 | pbclient.update_project(project) | 36 | pbclient.update_project(project) |
| 42 | - | 37 | + |
| 43 | def create_project(self): | 38 | def create_project(self): |
| 44 | app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] | 39 | app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] |
| 45 | project = self.__find_project(app_short_name) | 40 | project = self.__find_project(app_short_name) |
| @@ -51,30 +46,30 @@ class Wikilibras: | @@ -51,30 +46,30 @@ class Wikilibras: | ||
| 51 | if (project): | 46 | if (project): |
| 52 | self.__setup_project(project) | 47 | self.__setup_project(project) |
| 53 | result_msg = "The project " + app_short_name + " was created." | 48 | result_msg = "The project " + app_short_name + " was created." |
| 54 | - else: | 49 | + else: |
| 55 | result_msg = "The project " + app_short_name + " couldn't be created. Check the server log for details." | 50 | result_msg = "The project " + app_short_name + " couldn't be created. Check the server log for details." |
| 56 | pyutil.log(result_msg) | 51 | pyutil.log(result_msg) |
| 57 | - return result_msg | 52 | + return result_msg |
| 58 | 53 | ||
| 59 | - def update_project(self): | 54 | + def update_project(self): |
| 60 | app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] | 55 | app_short_name = self.config['PYBOSSA_APP_SHORT_NAME'] |
| 61 | project = self.__find_project(app_short_name) | 56 | project = self.__find_project(app_short_name) |
| 62 | self.__update_project_info(project) | 57 | self.__update_project_info(project) |
| 63 | result_msg = "The project " + app_short_name + " was updated." | 58 | result_msg = "The project " + app_short_name + " was updated." |
| 64 | pyutil.log(result_msg) | 59 | pyutil.log(result_msg) |
| 65 | return result_msg | 60 | return result_msg |
| 66 | - | 61 | + |
| 67 | def __find_task(self, project_id, task_id): | 62 | def __find_task(self, project_id, task_id): |
| 68 | tasks = pbclient.find_tasks(project_id, id=task_id) | 63 | tasks = pbclient.find_tasks(project_id, id=task_id) |
| 69 | return tasks[0] if len(tasks) > 0 else None | 64 | return tasks[0] if len(tasks) > 0 else None |
| 70 | - | 65 | + |
| 71 | def __find_taskruns(self, project_id, task_id): | 66 | def __find_taskruns(self, project_id, task_id): |
| 72 | return pbclient.find_taskruns(project_id, id=task_id) | 67 | return pbclient.find_taskruns(project_id, id=task_id) |
| 73 | - | 68 | + |
| 74 | def __number_of_taskruns(self, project_id, task_id): | 69 | def __number_of_taskruns(self, project_id, task_id): |
| 75 | taskruns = self.__find_taskruns(project_id, task_id) | 70 | taskruns = self.__find_taskruns(project_id, task_id) |
| 76 | return len(taskruns) | 71 | return len(taskruns) |
| 77 | - | 72 | + |
| 78 | def __close_task(self, project_id, task_id): | 73 | def __close_task(self, project_id, task_id): |
| 79 | pyutil.log("Closing the task with ID=" + str(task_id) + ".") | 74 | pyutil.log("Closing the task with ID=" + str(task_id) + ".") |
| 80 | task = self.__find_task(project_id, task_id) | 75 | task = self.__find_task(project_id, task_id) |
| @@ -82,15 +77,41 @@ class Wikilibras: | @@ -82,15 +77,41 @@ class Wikilibras: | ||
| 82 | task.n_answers = number_of_taskruns + 1 | 77 | task.n_answers = number_of_taskruns + 1 |
| 83 | pbclient.update_task(task) | 78 | pbclient.update_task(task) |
| 84 | return "The task with ID=" + str(task_id) + " was closed." | 79 | return "The task with ID=" + str(task_id) + " was closed." |
| 85 | - | 80 | + |
| 81 | + def get_file(self, url, filename): | ||
| 82 | + r = requests.get(url, stream = True) | ||
| 83 | + if (r.status_code == 200): | ||
| 84 | + with open(filename, 'wb') as f: | ||
| 85 | + for chunk in r.iter_content(chunk_size = 1024): | ||
| 86 | + if chunk: | ||
| 87 | + f.write(chunk) | ||
| 88 | + return True | ||
| 89 | + return False | ||
| 90 | + | ||
| 86 | def finish_task(self): | 91 | def finish_task(self): |
| 87 | task_id = request.form['task_id'] | 92 | task_id = request.form['task_id'] |
| 93 | + api_host = self.config['API_HOST'] | ||
| 94 | + api_dbhost = self.config['API_DB_HOST'] | ||
| 95 | + user_id = request.form['user_id'] | ||
| 96 | + sign_name = request.form['sign_name'] | ||
| 88 | project_id = request.form['project_id'] | 97 | project_id = request.form['project_id'] |
| 89 | number_of_approval = int(request.form['number_of_approval']) | 98 | number_of_approval = int(request.form['number_of_approval']) |
| 90 | agreement_number = self.config['AGREEMENT_NUMBER'] | 99 | agreement_number = self.config['AGREEMENT_NUMBER'] |
| 91 | result_msg = "" | 100 | result_msg = "" |
| 92 | code = 200 | 101 | code = 200 |
| 93 | if (number_of_approval >= agreement_number): | 102 | if (number_of_approval >= agreement_number): |
| 103 | + tmp_dir = tempfile.NamedTemporaryFile().name | ||
| 104 | + if not os.path.exists(tmp_dir): | ||
| 105 | + os.makedirs(tmp_dir) | ||
| 106 | + blend_path = os.path.join(tmp_dir, sign_name + ".blend") | ||
| 107 | + video_path = os.path.join(tmp_dir, sign_name + ".webm") | ||
| 108 | + blend_downloaded = self.get_file(('%s/public/%s/%s.blend' % (api_host, user_id, sign_name)), blend_path) | ||
| 109 | + video_downloaded = self.get_file(('%s/public/%s/%s.webm' % (api_host, user_id, sign_name)), video_path) | ||
| 110 | + if (blend_downloaded and video_downloaded): | ||
| 111 | + files = [ ("video", (video_path, open(video_path,"rb"))), ("video", (blend_path, open(blend_path, "rb"))) ] | ||
| 112 | + values = { "nome": sign_name, "selo": 1, "wikilibras": True, "overwrite": True } | ||
| 113 | + r = requests.post(("%s/addsinal" % (api_dbhost)), files=files, data=values) | ||
| 114 | + shutil.rmtree(tmp_dir) | ||
| 94 | result_msg = self.__close_task(project_id, task_id) | 115 | result_msg = self.__close_task(project_id, task_id) |
| 95 | else: | 116 | else: |
| 96 | result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." | 117 | result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." |