Code changes for sql-to-api branch
This commit is contained in:
+36
-8
@@ -139,10 +139,13 @@ def get_client_uuid_by_name(client_name, user_id):
|
||||
query = ("select uuid from oc_timemanager_client where name=\""+client_name+"\" AND user_id=\""+user_id+"\"")
|
||||
cursor.execute(query)
|
||||
|
||||
client_uuid = cursor.fetchone()[0]
|
||||
row = cursor.fetchone()
|
||||
save_db()
|
||||
|
||||
return client_uuid.decode('utf-8')
|
||||
if not row:
|
||||
return None
|
||||
|
||||
return row[0].decode('utf-8')
|
||||
|
||||
|
||||
def get_project_uuid_by_name(project_name, client_uuid, user_id):
|
||||
@@ -314,12 +317,25 @@ def create_client(name):
|
||||
|
||||
# Vérification de la réponse
|
||||
if response.status_code == 200:
|
||||
pass
|
||||
#print("Client créé avec succès.")
|
||||
#print(json.dumps(response.json(), indent=1))
|
||||
try:
|
||||
resp = response.json()
|
||||
# Tenter d'extraire l'UUID renvoyé par l'API (structure attendue)
|
||||
client_uuid = None
|
||||
if isinstance(resp, dict):
|
||||
client_created = resp.get('data', {}).get('clients', {}).get('created', [])
|
||||
if client_created and isinstance(client_created, list):
|
||||
client_uuid = client_created[0].get('uuid')
|
||||
|
||||
if client_uuid:
|
||||
return client_uuid
|
||||
# si pas d'uuid dans la réponse, retourner None (le caller gérera)
|
||||
return None
|
||||
except Exception:
|
||||
return None
|
||||
else:
|
||||
print("Erreur de création client")
|
||||
print(response.reason)
|
||||
return None
|
||||
|
||||
|
||||
def insert_task_time(name, project_name, client_name, task_uuid, user_id, dstart, hstart, dend, hend):
|
||||
@@ -422,11 +438,23 @@ for user_info in config['calendars']:
|
||||
continue
|
||||
|
||||
# Description => Client
|
||||
client_uuid = None
|
||||
if not client_exist_by_name(client_name, user_id):
|
||||
print("Création du client {}".format(client_name))
|
||||
create_client(client_name)
|
||||
|
||||
client_uuid = get_client_uuid_by_name(client_name, user_id)
|
||||
created_uuid = create_client(client_name)
|
||||
if created_uuid:
|
||||
client_uuid = created_uuid
|
||||
else:
|
||||
# tentative de récupération depuis la base au cas où l'API a créé l'entrée
|
||||
client_uuid = get_client_uuid_by_name(client_name, user_id)
|
||||
if not client_uuid:
|
||||
print("Erreur: impossible d'obtenir l'UUID du client '{}' après création, saut.".format(client_name))
|
||||
continue
|
||||
else:
|
||||
client_uuid = get_client_uuid_by_name(client_name, user_id)
|
||||
if not client_uuid:
|
||||
print("Erreur: le client '{}' existe mais son UUID est introuvable, saut.".format(client_name))
|
||||
continue
|
||||
|
||||
# Categories => Project
|
||||
if not project_exist_by_name(project_name, client_uuid, user_id):
|
||||
|
||||
Reference in New Issue
Block a user