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 1 # -*- coding: UTF-8 -*-
2 2  
3 3 import json
4   -import os
5 4 import pbclient
6 5 import pyutil
7 6 import requests
8   -import shutil
9 7 import logging
10 8  
  9 +
11 10 class task_creator():
12 11 def __init__(self, json_data):
13 12 self.data = {}
... ... @@ -30,23 +29,23 @@ class task_creator():
30 29 pbclient.set('endpoint', self.data["pb_endpoint"])
31 30  
32 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 33 if (len(projects) > 0):
35 34 return projects[0].id
36 35 else:
37 36 return None
38 37  
39 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 41 def __get__(self, endpoint):
43 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 44 return r
46 45 except:
47 46 return {}
48 47  
49   - def get_newtasks(self, selo = None):
  48 + def get_newtasks(self, selo=None):
50 49 url = "newtasks?task_manager_alive=true"
51 50 if (isinstance(selo, int)):
52 51 url += "?selo=%d" % (selo)
... ... @@ -79,35 +78,45 @@ class task_creator():
79 78 blend_file = i["blender"]
80 79 video_ref = i["file"]
81 80 video_ava = i["avatar"]
  81 +
82 82 proj_name = None
  83 + proj_id = None
  84 +
83 85 if (id_selo == 7):
84   - proj_name = "wikilibras";
  86 + proj_name = "wikilibras"
85 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 91 else:
90 92 continue
  93 +
91 94 proj_id = self.data[proj_name]["project_id"]
92 95 public_users = "/public/users"
93   - if (usuario != None):
  96 +
  97 + if (usuario is not None):
94 98 public_users += "/" + usuario
95   - if (estado != None):
  99 + if (estado is not None):
96 100 public_users += "/" + estado
97   - if (classe != None):
  101 + if (classe is not None):
98 102 public_users += "/" + classe
  103 +
99 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 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 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 116 task["blend"] = ("%s/%s" % (public_users, blend_file))
  117 +
109 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 120 response_task = pbclient.create_task(proj_id, task)
112 121 pyutil.log("[%s] created task[%d] '%s'" % (proj_name, int(response_task.id), nome_sinal))
113 122 # TODO
... ...