[DEV] add element with correct group and saison

This commit is contained in:
Edouard DUPIN 2019-12-11 23:38:23 +01:00
parent dd37aae306
commit 6ddfd86b1c
4 changed files with 72 additions and 31 deletions

View File

@ -152,6 +152,18 @@ def add_group(_app, _name_api):
async def create(request):
return response.json(data_global_elements.get_interface(_name_api).post(request.json))
@elem_blueprint.post('/' + _name_api + "/find", strict_slashes=True)
@doc.summary("Create new resource if the name does not already exist")
@doc.description("Store a newly created resource in storage.")
@doc.consumes(DataModel, location='body')#, required=True)
@doc.response_success(status=201, description='If successful created')
async def find_with_name(request):
api = data_global_elements.get_interface(_name_api)
for elem in api.bdd:
if elem["name"] == request.json["name"]:
return response.json({"id": elem["id"]})
raise ServerError("No data found", status_code=404)
@elem_blueprint.get('/' + _name_api + '/<id:int>', strict_slashes=True)
@doc.summary("Show resources")
@doc.description("Display a listing of the resource.")
@ -184,6 +196,8 @@ def add_group(_app, _name_api):
add_group(app, API_GROUP)
def add_saison(_app, _name_api):
elem_blueprint = Blueprint(_name_api)
@ -206,6 +220,19 @@ def add_saison(_app, _name_api):
async def create(request):
return response.json(data_global_elements.get_interface(_name_api).post(request.json))
@elem_blueprint.post('/' + _name_api + "/find", strict_slashes=True)
@doc.summary("find a season existance")
@doc.description("return the ID of the season table.")
@doc.consumes(DataModel, location='body')
@doc.response_success(status=201, description='If successful created')
async def find_with_name(request):
api = data_global_elements.get_interface(_name_api)
for elem in api.bdd:
if elem["group_id"] == request.json["group_id"] \
and elem["number"] == request.json["number"]:
return response.json({"id": elem["id"]})
raise ServerError("No data found", status_code=404)
@elem_blueprint.get('/' + _name_api + '/<id:int>', strict_slashes=True)
@doc.summary("Show resources")
@doc.description("Display a listing of the resource.")
@ -243,7 +270,7 @@ def add_video(_app, _name_api):
class DataModel:
type_id = int
saison = int
saison_id = int
episode = int
group_id = int
name = str
@ -266,6 +293,10 @@ def add_video(_app, _name_api):
@doc.consumes(DataModel, location='body')#, required=True)
@doc.response_success(status=201, description='If successful created')
async def create(request):
"""
if "group_name" in request.json.keys():
id_group = data_global_elements.get_interface(API_GROUP).find_or_create_name(request.json["group_name"])
"""
return response.json(data_global_elements.get_interface(_name_api).post(request.json))
@elem_blueprint.get('/' + _name_api + '/<id:int>', strict_slashes=True)

View File

@ -8,8 +8,6 @@
## @license MPL v2.0 (see license file)
##
global_id = 0;
import tools
import json
from realog import debug
@ -20,19 +18,20 @@ class DataInterface():
self.file = _file
self.bdd = []
self.need_save = False
self.last_id = 0
if tools.exist(self.file) == False:
self.need_save = True
else:
data = tools.file_read_data(self.file)
self.bdd = json.loads(data)
self.upgrade_global_bdd_id();
def upgrade_global_bd_id(self):
global global_id
def upgrade_global_bdd_id(self):
for elem in self.bdd:
if 'id' not in elem.keys():
continue
if elem["id"] >= global_id:
global_id = elem["id"] + 1
if elem["id"] >= self.last_id:
self.last_id = elem["id"] + 1
def get_table_index(id):
id_in_bdd = 0
@ -84,9 +83,8 @@ class DataInterface():
def post(self, value):
debug.info("post " + self.name)
global global_id
value["id"] = global_id
global_id += 1
value["id"] = self.last_id
self.last_id += 1
self.bdd.append(value)
self.need_save = True
return value

View File

@ -257,30 +257,24 @@ def push_video_file(_path, _basic_key={}):
# Other title
_basic_key.set["title2"] = it;
# remove unneeded date
if have_date == False:
_basic_key["date"] = ""
# remove unneeded title 2
if have_Title == False:
_basic_key["title2"] = ""
# Remove the actors [XXX YYY][EEE TTT]...
file_name, acthors = extract_and_remove(file_name, '[', ']');
if len(acthors) > 0:
file_name, actors = extract_and_remove(file_name, '[', ']');
if len(actors) > 0:
debug.info(" '" + file_name + "'")
actor_list = []
for it_actor in acthors:
for it_actor in actors:
if actor_list != "":
actor_list += ";"
actor_list.append(it_actor)
_basic_key["acthors"] = actor_list
_basic_key["actors"] = actor_list
list_element_base = file_name.split('-')
debug.warning("==> Title file: " + file_name)
debug.warning("==> Title cut : " + str(list_element_base))
list_element = [];
tmp_start_string = "";
for iii in range(0,len(list_element_base)):
iii = 0
while iii <len(list_element_base):
if list_element_base[iii][0] != 's' \
and list_element_base[iii][0] != 'e':
if tmp_start_string != "":
@ -292,9 +286,14 @@ def push_video_file(_path, _basic_key={}):
while iii<len(list_element_base):
list_element.append(list_element_base[iii])
iii += 1
iii += 1
debug.warning("==> start elem: " + str(tmp_start_string))
if tmp_start_string != "":
list_element.append(tmp_start_string)
debug.warning("==> list_element : " + str(list_element))
if len(list_element) == 1:
# nothing to do , it might be a film ...
@ -359,18 +358,31 @@ def push_video_file(_path, _basic_key={}):
data_model = {
"type_id": _basic_key["type"],
"sha512": result_send_data_json["sha512"],
"saison": _basic_key["saison"],
"episode": _basic_key["episode"],
"group_name": _basic_key["series-name"],
#"group_id": int,
"name": _basic_key["title"],
"description": None,
# creating time
"date": _basic_key["date"],
"actors": _basic_key["acthors"],
# number of second
"time": None,
}
for elem in ["actors", "date", "description", "episode", "title2"]:
if elem in _basic_key.keys():
data_model[elem] = _basic_key[elem]
if "series-name" in _basic_key.keys():
result_group_data = requests.post("http://127.0.0.1:15080/group/find", data=json.dumps({"name":_basic_key["series-name"]}, sort_keys=True, indent=4))
print("Create group ??? *********** : " + str(result_group_data) + " " + result_group_data.text)
if result_group_data.status_code == 404:
result_group_data = requests.post("http://127.0.0.1:15080/group", data=json.dumps({"name":_basic_key["series-name"]}, sort_keys=True, indent=4))
print("yes we create new group *********** : " + str(result_group_data) + " " + result_group_data.text)
group_id = result_group_data.json()["id"]
data_model["group_id"] = group_id
if "saison" in _basic_key.keys():
result_saison_data = requests.post("http://127.0.0.1:15080/saison/find", data=json.dumps({"number":_basic_key["saison"], "group_id":group_id}, sort_keys=True, indent=4))
print("Create saison ??? *********** : " + str(result_saison_data) + " " + result_saison_data.text)
if result_saison_data.status_code == 404:
result_saison_data = requests.post("http://127.0.0.1:15080/saison", data=json.dumps({"number":_basic_key["saison"], "group_id":group_id}, sort_keys=True, indent=4))
print("yes we create new saison *********** : " + str(result_saison_data) + " " + result_saison_data.text)
saison_id = result_saison_data.json()["id"]
data_model["saison_id"] = saison_id
result_send_data = requests.post("http://127.0.0.1:15080/video", data=json.dumps(data_model, sort_keys=True, indent=4))
print("result *********** : " + str(result_send_data) + " " + result_send_data.text)