Commit c2702d12506f556a2504a722ac47bfe961abb1b1
1 parent
4c2ea1e6
Exists in
master
Atualiza endpoint do banco de sinais
Showing
1 changed file
with
22 additions
and
18 deletions
Show diff stats
corretor.py
... | ... | @@ -10,17 +10,18 @@ import requests |
10 | 10 | import shutil |
11 | 11 | import tempfile |
12 | 12 | |
13 | + | |
13 | 14 | class Corretor: |
14 | 15 | |
15 | 16 | def __init__(self, configuration, template_env): |
16 | - self.config = configuration | |
17 | - self.env = template_env | |
18 | - self.__setup_pb_client() | |
19 | - self.__setup_upload_folder() | |
17 | + self.config = configuration | |
18 | + self.env = template_env | |
19 | + self.__setup_pb_client() | |
20 | + self.__setup_upload_folder() | |
20 | 21 | |
21 | 22 | def __setup_pb_client(self): |
22 | - pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) | |
23 | - pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) | |
23 | + pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT']) | |
24 | + pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) | |
24 | 25 | |
25 | 26 | def __setup_upload_folder(self): |
26 | 27 | upload_folder = self.config['UPLOAD_FOLDER'] |
... | ... | @@ -41,16 +42,16 @@ class Corretor: |
41 | 42 | video_ava = "/videos/" + sign + "_AVATAR.webm" |
42 | 43 | blend = "/videos/" + sign + "_AVATAR.blend" |
43 | 44 | task = dict(sign_name=sign, submission_date=pyutil.get_date_now(), |
44 | - video_ref=video_ref, video_ava=video_ava, blend=blend) | |
45 | + video_ref=video_ref, video_ava=video_ava, blend=blend) | |
45 | 46 | pbclient.create_task(project.id, task) |
46 | 47 | |
47 | 48 | def __update_project_info(self, project): |
48 | 49 | template = self.env.get_template('index.html') |
49 | 50 | project.info['task_presenter'] = template.render( |
50 | - server=self.config['HOST_STATIC_FILES_ENDPOINT'], | |
51 | - server_backend=self.config['HOST_ENDPOINT'], | |
52 | - app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'], | |
53 | - api_db_host=self.config['API_DB_HOST']) | |
51 | + server=self.config['HOST_STATIC_FILES_ENDPOINT'], | |
52 | + server_backend=self.config['HOST_ENDPOINT'], | |
53 | + app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'], | |
54 | + api_db_host=self.config['API_DB_HOST']) | |
54 | 55 | project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" |
55 | 56 | project.info['sched'] = "incremental" |
56 | 57 | project.info['published'] = True |
... | ... | @@ -104,21 +105,24 @@ class Corretor: |
104 | 105 | pyutil.log("video file: %s was not downloaded" % (video_url)) |
105 | 106 | else: |
106 | 107 | files_to_upload = [ |
107 | - ("video", (video_path, open(video_path,"rb"))), | |
108 | + ("video", (video_path, open(video_path, "rb"))), | |
108 | 109 | ("video", (blend_path, open(blend_path, "rb"))) |
109 | 110 | ] |
110 | 111 | body = { |
111 | 112 | "nome": sign_name, |
112 | - "idTask": task_id, | |
113 | + "idtask": task_id, | |
113 | 114 | "selo": 5 |
114 | 115 | } |
115 | 116 | r = requests.post(("%s/updatesinal" % (api_dbhost)), files=files_to_upload, data=body) |
116 | - pyutil.log(r.text) | |
117 | + code = r.status_code | |
118 | + if (code == 200): | |
119 | + result_msg = self.__close_task(project_id, task_id) | |
120 | + else: | |
121 | + result_msg = r.text | |
117 | 122 | shutil.rmtree(tmp_dir) |
118 | - result_msg = self.__close_task(project_id, task_id) | |
119 | 123 | else: |
120 | 124 | result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." |
121 | - pyutil.log(result_msg) | |
125 | + pyutil.log(str(result_msg).encode("UTF-8", errors="ignore")) | |
122 | 126 | return make_response(result_msg, code) |
123 | 127 | |
124 | 128 | def render_video(self): |
... | ... | @@ -169,10 +173,10 @@ class Corretor: |
169 | 173 | return '.' in filename and filename.rsplit('.', 1)[1] in allowed_extensions |
170 | 174 | |
171 | 175 | def get_file(self, url, filename): |
172 | - r = requests.get(url, stream = True) | |
176 | + r = requests.get(url, stream=True) | |
173 | 177 | if (r.status_code == 200): |
174 | 178 | with open(filename, 'wb') as f: |
175 | - for chunk in r.iter_content(chunk_size = 1024): | |
179 | + for chunk in r.iter_content(chunk_size=1024): | |
176 | 180 | if chunk: |
177 | 181 | f.write(chunk) |
178 | 182 | return True | ... | ... |