Commit 43126a4a32e278b5536f4cd9f5cdf56881c0302e

Authored by André Araújo
1 parent 1ef47e53
Exists in master

Adiciona video_ref na criação da task para o corretor

Showing 1 changed file with 28 additions and 19 deletions   Show diff stats
task_manager.py
1 # -*- coding: UTF-8 -*- 1 # -*- coding: UTF-8 -*-
2 2
3 import json 3 import json
4 -import os  
5 import pbclient 4 import pbclient
6 import pyutil 5 import pyutil
7 import requests 6 import requests
8 -import shutil  
9 import logging 7 import logging
10 8
  9 +
11 class task_creator(): 10 class task_creator():
12 def __init__(self, json_data): 11 def __init__(self, json_data):
13 self.data = {} 12 self.data = {}
@@ -30,23 +29,23 @@ class task_creator(): @@ -30,23 +29,23 @@ class task_creator():
30 pbclient.set('endpoint', self.data["pb_endpoint"]) 29 pbclient.set('endpoint', self.data["pb_endpoint"])
31 30
32 def get_pb_project_id(self, pb_short_name): 31 def get_pb_project_id(self, pb_short_name):
33 - projects = pbclient.find_project(short_name = pb_short_name) 32 + projects = pbclient.find_project(short_name=pb_short_name)
34 if (len(projects) > 0): 33 if (len(projects) > 0):
35 return projects[0].id 34 return projects[0].id
36 else: 35 else:
37 return None 36 return None
38 37
39 def to_string(self): 38 def to_string(self):
40 - return json.dumps(self.data, sort_keys = True, ensure_ascii = False, indent = 4) 39 + return json.dumps(self.data, sort_keys=True, ensure_ascii=False, indent=4)
41 40
42 def __get__(self, endpoint): 41 def __get__(self, endpoint):
43 try: 42 try:
44 - r = requests.get(('http://%s:%s/%s' % (self.data["db_host"], self.data["db_port"], endpoint)), timeout = self.data["db_timeout"]) 43 + r = requests.get(('http://%s:%s/%s' % (self.data["db_host"], self.data["db_port"], endpoint)), timeout=self.data["db_timeout"])
45 return r 44 return r
46 except: 45 except:
47 return {} 46 return {}
48 47
49 - def get_newtasks(self, selo = None): 48 + def get_newtasks(self, selo=None):
50 url = "newtasks?task_manager_alive=true" 49 url = "newtasks?task_manager_alive=true"
51 if (isinstance(selo, int)): 50 if (isinstance(selo, int)):
52 url += "?selo=%d" % (selo) 51 url += "?selo=%d" % (selo)
@@ -79,35 +78,45 @@ class task_creator(): @@ -79,35 +78,45 @@ class task_creator():
79 blend_file = i["blender"] 78 blend_file = i["blender"]
80 video_ref = i["file"] 79 video_ref = i["file"]
81 video_ava = i["avatar"] 80 video_ava = i["avatar"]
  81 +
82 proj_name = None 82 proj_name = None
  83 + proj_id = None
  84 +
83 if (id_selo == 7): 85 if (id_selo == 7):
84 - proj_name = "wikilibras"; 86 + proj_name = "wikilibras"
85 elif (id_selo == 4): 87 elif (id_selo == 4):
86 - proj_name = "corretor";  
87 - elif ((id_selo == 1) or (id_selo == 5)):  
88 - proj_name = "validador"; 88 + proj_name = "corretor"
  89 + elif (id_selo in [1, 5]):
  90 + proj_name = "validador"
89 else: 91 else:
90 continue 92 continue
  93 +
91 proj_id = self.data[proj_name]["project_id"] 94 proj_id = self.data[proj_name]["project_id"]
92 public_users = "/public/users" 95 public_users = "/public/users"
93 - if (usuario != None): 96 +
  97 + if (usuario is not None):
94 public_users += "/" + usuario 98 public_users += "/" + usuario
95 - if (estado != None): 99 + if (estado is not None):
96 public_users += "/" + estado 100 public_users += "/" + estado
97 - if (classe != None): 101 + if (classe is not None):
98 public_users += "/" + classe 102 public_users += "/" + classe
  103 +
99 task = dict( 104 task = dict(
100 - sign_name = nome_sinal,  
101 - submission_date = pyutil.get_date_now() 105 + sign_name=nome_sinal,
  106 + submission_date=pyutil.get_date_now()
102 ) 107 )
103 - if (video_ref != None): 108 +
  109 + if ((video_ref is not None) and (id_selo in [4, 1, 5, 7])):
104 task["video_ref"] = ("%s/%s" % (public_users, video_ref)) 110 task["video_ref"] = ("%s/%s" % (public_users, video_ref))
105 - if (video_ava != None): 111 +
  112 + if ((video_ava is not None) and (id_selo in [4, 1, 5])):
106 task["video_ava"] = ("%s/%s" % (public_users, video_ava)) 113 task["video_ava"] = ("%s/%s" % (public_users, video_ava))
107 - if (blend_file != None): 114 +
  115 + if ((blend_file is not None) and (id_selo in [4])):
108 task["blend"] = ("%s/%s" % (public_users, blend_file)) 116 task["blend"] = ("%s/%s" % (public_users, blend_file))
  117 +
109 # print(repr(task).decode("unicode-escape")) 118 # print(repr(task).decode("unicode-escape"))
110 - # print(json.dumps(task, ensure_ascii = True, indent = 4, sort_keys = False)) 119 + # print(json.dumps(task, ensure_ascii=True, indent=4, sort_keys=False))
111 response_task = pbclient.create_task(proj_id, task) 120 response_task = pbclient.create_task(proj_id, task)
112 pyutil.log("[%s] created task[%d] '%s'" % (proj_name, int(response_task.id), nome_sinal)) 121 pyutil.log("[%s] created task[%d] '%s'" % (proj_name, int(response_task.id), nome_sinal))
113 # TODO 122 # TODO