Commit c2702d12506f556a2504a722ac47bfe961abb1b1

Authored by André Araújo
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
@@ -10,17 +10,18 @@ import requests @@ -10,17 +10,18 @@ import requests
10 import shutil 10 import shutil
11 import tempfile 11 import tempfile
12 12
  13 +
13 class Corretor: 14 class Corretor:
14 15
15 def __init__(self, configuration, template_env): 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 def __setup_pb_client(self): 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 def __setup_upload_folder(self): 26 def __setup_upload_folder(self):
26 upload_folder = self.config['UPLOAD_FOLDER'] 27 upload_folder = self.config['UPLOAD_FOLDER']
@@ -41,16 +42,16 @@ class Corretor: @@ -41,16 +42,16 @@ class Corretor:
41 video_ava = "/videos/" + sign + "_AVATAR.webm" 42 video_ava = "/videos/" + sign + "_AVATAR.webm"
42 blend = "/videos/" + sign + "_AVATAR.blend" 43 blend = "/videos/" + sign + "_AVATAR.blend"
43 task = dict(sign_name=sign, submission_date=pyutil.get_date_now(), 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 pbclient.create_task(project.id, task) 46 pbclient.create_task(project.id, task)
46 47
47 def __update_project_info(self, project): 48 def __update_project_info(self, project):
48 template = self.env.get_template('index.html') 49 template = self.env.get_template('index.html')
49 project.info['task_presenter'] = template.render( 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 project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" 55 project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png"
55 project.info['sched'] = "incremental" 56 project.info['sched'] = "incremental"
56 project.info['published'] = True 57 project.info['published'] = True
@@ -104,21 +105,24 @@ class Corretor: @@ -104,21 +105,24 @@ class Corretor:
104 pyutil.log("video file: %s was not downloaded" % (video_url)) 105 pyutil.log("video file: %s was not downloaded" % (video_url))
105 else: 106 else:
106 files_to_upload = [ 107 files_to_upload = [
107 - ("video", (video_path, open(video_path,"rb"))), 108 + ("video", (video_path, open(video_path, "rb"))),
108 ("video", (blend_path, open(blend_path, "rb"))) 109 ("video", (blend_path, open(blend_path, "rb")))
109 ] 110 ]
110 body = { 111 body = {
111 "nome": sign_name, 112 "nome": sign_name,
112 - "idTask": task_id, 113 + "idtask": task_id,
113 "selo": 5 114 "selo": 5
114 } 115 }
115 r = requests.post(("%s/updatesinal" % (api_dbhost)), files=files_to_upload, data=body) 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 shutil.rmtree(tmp_dir) 122 shutil.rmtree(tmp_dir)
118 - result_msg = self.__close_task(project_id, task_id)  
119 else: 123 else:
120 result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." 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 return make_response(result_msg, code) 126 return make_response(result_msg, code)
123 127
124 def render_video(self): 128 def render_video(self):
@@ -169,10 +173,10 @@ class Corretor: @@ -169,10 +173,10 @@ class Corretor:
169 return '.' in filename and filename.rsplit('.', 1)[1] in allowed_extensions 173 return '.' in filename and filename.rsplit('.', 1)[1] in allowed_extensions
170 174
171 def get_file(self, url, filename): 175 def get_file(self, url, filename):
172 - r = requests.get(url, stream = True) 176 + r = requests.get(url, stream=True)
173 if (r.status_code == 200): 177 if (r.status_code == 200):
174 with open(filename, 'wb') as f: 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 if chunk: 180 if chunk:
177 f.write(chunk) 181 f.write(chunk)
178 return True 182 return True