diff --git a/corretor.py b/corretor.py index 6805560..0099fa9 100644 --- a/corretor.py +++ b/corretor.py @@ -10,17 +10,18 @@ import requests import shutil import tempfile + class Corretor: def __init__(self, configuration, template_env): - self.config = configuration - self.env = template_env - self.__setup_pb_client() - self.__setup_upload_folder() + self.config = configuration + self.env = template_env + self.__setup_pb_client() + self.__setup_upload_folder() def __setup_pb_client(self): - pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) - pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) + pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) + pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) def __setup_upload_folder(self): upload_folder = self.config['UPLOAD_FOLDER'] @@ -41,16 +42,16 @@ class Corretor: video_ava = "/videos/" + sign + "_AVATAR.webm" blend = "/videos/" + sign + "_AVATAR.blend" task = dict(sign_name=sign, submission_date=pyutil.get_date_now(), - video_ref=video_ref, video_ava=video_ava, blend=blend) + video_ref=video_ref, video_ava=video_ava, blend=blend) pbclient.create_task(project.id, task) def __update_project_info(self, project): template = self.env.get_template('index.html') 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_db_host=self.config['API_DB_HOST']) + server=self.config['HOST_STATIC_FILES_ENDPOINT'], + server_backend=self.config['HOST_ENDPOINT'], + app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'], + api_db_host=self.config['API_DB_HOST']) project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" project.info['sched'] = "incremental" project.info['published'] = True @@ -104,21 +105,24 @@ class Corretor: pyutil.log("video file: %s was not downloaded" % (video_url)) else: files_to_upload = [ - ("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": 5 } r = requests.post(("%s/updatesinal" % (api_dbhost)), files=files_to_upload, data=body) - pyutil.log(r.text) + code = r.status_code + if (code == 200): + result_msg = self.__close_task(project_id, task_id) + else: + result_msg = r.text shutil.rmtree(tmp_dir) - result_msg = self.__close_task(project_id, task_id) 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) def render_video(self): @@ -169,10 +173,10 @@ class Corretor: return '.' in filename and filename.rsplit('.', 1)[1] in allowed_extensions def get_file(self, url, filename): - r = requests.get(url, stream = True) + r = requests.get(url, stream=True) if (r.status_code == 200): with open(filename, 'wb') as f: - for chunk in r.iter_content(chunk_size = 1024): + for chunk in r.iter_content(chunk_size=1024): if chunk: f.write(chunk) return True -- libgit2 0.21.2