diff --git a/wikilibras.py b/wikilibras.py index fca6516..d080295 100644 --- a/wikilibras.py +++ b/wikilibras.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from flask import request, make_response from werkzeug import secure_filename +import json import pbclient import os import pyutil @@ -121,23 +122,36 @@ class Wikilibras: os.makedirs(tmp_dir) blend_path = os.path.join(tmp_dir, sign_name + ".blend") video_path = os.path.join(tmp_dir, sign_name + ".webm") - blend_downloaded = self.get_file(('%s/public/%s/%s.blend' % (api_host, user_id, sign_name)), blend_path) - video_downloaded = self.get_file(('%s/public/%s/%s.webm' % (api_host, user_id, sign_name)), video_path) - if (blend_downloaded and video_downloaded): + blend_url = '%s/public/%s/%s.blend' % (api_host, user_id, sign_name) + video_url = '%s/public/%s/%s.webm' % (api_host, user_id, sign_name) + blend_downloaded = self.get_file(blend_url, blend_path) + video_downloaded = self.get_file(video_url, video_path) + if (not blend_downloaded): + pyutil.log("blend file: %s was not downloaded" % (blend_url)) + elif (not video_downloaded): + pyutil.log("video file: %s was not downloaded" % (video_url)) + else: files = [ - ("video", (video_path, open(video_path,"rb"))), + ("video", (video_path, open(video_path, "rb"))), ("video", (blend_path, open(blend_path, "rb"))) ] body = { "nome": sign_name, - "idTask": task_id, + "idtask": task_id, "selo": 1 } - r = requests.post(("%s/updatesinal" % (api_dbhost)), files=files, data=body) - pyutil.log(r.text) + r = requests.post( + "%s/updatesinal" % (api_dbhost), + files=files, + data=body + ) shutil.rmtree(tmp_dir) - result_msg = self.__close_task(project_id, task_id) + code = r.status_code + if (code == 200): + result_msg = self.__close_task(project_id, task_id) + else: + result_msg = r.text else: result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." - pyutil.log(result_msg) + pyutil.log(str(result_msg).encode("UTF-8", errors="ignore")) return make_response(result_msg, code) -- libgit2 0.21.2