Commit 8d6ddff62ef513819bb85dddea13a6a1c32eeb73
1 parent
b182bd13
Exists in
master
Corrige finish task
Showing
1 changed file
with
23 additions
and
9 deletions
Show diff stats
wikilibras.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | from flask import request, make_response |
3 | 3 | from werkzeug import secure_filename |
4 | +import json | |
4 | 5 | import pbclient |
5 | 6 | import os |
6 | 7 | import pyutil |
... | ... | @@ -121,23 +122,36 @@ class Wikilibras: |
121 | 122 | os.makedirs(tmp_dir) |
122 | 123 | blend_path = os.path.join(tmp_dir, sign_name + ".blend") |
123 | 124 | video_path = os.path.join(tmp_dir, sign_name + ".webm") |
124 | - blend_downloaded = self.get_file(('%s/public/%s/%s.blend' % (api_host, user_id, sign_name)), blend_path) | |
125 | - video_downloaded = self.get_file(('%s/public/%s/%s.webm' % (api_host, user_id, sign_name)), video_path) | |
126 | - if (blend_downloaded and video_downloaded): | |
125 | + blend_url = '%s/public/%s/%s.blend' % (api_host, user_id, sign_name) | |
126 | + video_url = '%s/public/%s/%s.webm' % (api_host, user_id, sign_name) | |
127 | + blend_downloaded = self.get_file(blend_url, blend_path) | |
128 | + video_downloaded = self.get_file(video_url, video_path) | |
129 | + if (not blend_downloaded): | |
130 | + pyutil.log("blend file: %s was not downloaded" % (blend_url)) | |
131 | + elif (not video_downloaded): | |
132 | + pyutil.log("video file: %s was not downloaded" % (video_url)) | |
133 | + else: | |
127 | 134 | files = [ |
128 | - ("video", (video_path, open(video_path,"rb"))), | |
135 | + ("video", (video_path, open(video_path, "rb"))), | |
129 | 136 | ("video", (blend_path, open(blend_path, "rb"))) |
130 | 137 | ] |
131 | 138 | body = { |
132 | 139 | "nome": sign_name, |
133 | - "idTask": task_id, | |
140 | + "idtask": task_id, | |
134 | 141 | "selo": 1 |
135 | 142 | } |
136 | - r = requests.post(("%s/updatesinal" % (api_dbhost)), files=files, data=body) | |
137 | - pyutil.log(r.text) | |
143 | + r = requests.post( | |
144 | + "%s/updatesinal" % (api_dbhost), | |
145 | + files=files, | |
146 | + data=body | |
147 | + ) | |
138 | 148 | shutil.rmtree(tmp_dir) |
139 | - result_msg = self.__close_task(project_id, task_id) | |
149 | + code = r.status_code | |
150 | + if (code == 200): | |
151 | + result_msg = self.__close_task(project_id, task_id) | |
152 | + else: | |
153 | + result_msg = r.text | |
140 | 154 | else: |
141 | 155 | result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." |
142 | - pyutil.log(result_msg) | |
156 | + pyutil.log(str(result_msg).encode("UTF-8", errors="ignore")) | |
143 | 157 | return make_response(result_msg, code) | ... | ... |