14:31extract

This commit is contained in:
Ladebeze66 2025-04-03 14:31:56 +02:00
parent 7fa35fe108
commit be2c9e8a6c
10 changed files with 140 additions and 138 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

File diff suppressed because one or more lines are too long

View File

@ -1,9 +0,0 @@
{
"date_extraction": "2025-04-03T14:20:14.786086",
"ticket_dir": "output/ticket_T11067",
"fichiers_json": [
"ticket_info.json",
"all_messages.json",
"attachments_info.json"
]
}

View File

@ -1,14 +0,0 @@
{
"id": 11046,
"name": "changement nom centrale d'enrobage",
"description": "<p><br></p>",
"stage_id": [
8,
"Clôturé"
],
"user_id": [
32,
"Romuald GRUSON"
],
"create_date": "2025-03-18 13:22:27"
}

75
utils/data_extractor.py Normal file
View File

@ -0,0 +1,75 @@
import os
from datetime import datetime
from typing import Dict, Any
from .auth_manager import AuthManager
from .message_manager import MessageManager
from .attachment_manager import AttachmentManager
from .utils import save_json
class DataExtractor:
def __init__(self, auth_manager: AuthManager):
self.auth_manager = auth_manager
self.message_manager = MessageManager(auth_manager)
self.attachment_manager = AttachmentManager(auth_manager)
self.model_name = "project.task"
def get_ticket_by_code(self, ticket_code: str) -> Dict[str, Any]:
params = {
"model": self.model_name,
"method": "search_read",
"args": [[["code", "=", ticket_code]],
["id", "name", "description", "stage_id", "project_id", "partner_id",
"user_id", "date_start", "date_end", "create_date", "write_date",
"message_ids", "message_follower_ids", "attachment_ids", "timesheet_ids"]],
"kwargs": {"limit": 1}
}
result = self.auth_manager.rpc_call("/web/dataset/call_kw", params)
if isinstance(result, list) and len(result) > 0:
return result[0]
else:
print(f"Aucun ticket trouvé avec le code {ticket_code}")
return {}
def extract_ticket_data(self, ticket_code: str, output_dir: str):
os.makedirs(output_dir, exist_ok=True)
ticket_data = self.get_ticket_by_code(ticket_code)
if not ticket_data or "id" not in ticket_data:
print(f"Erreur: Ticket non trouvé.")
return None
# Sauvegarder ticket_info.json
ticket_info_path = os.path.join(output_dir, "ticket_info.json")
save_json(ticket_data, ticket_info_path)
# Sauvegarde des messages
messages_data = self.message_manager.get_ticket_messages(ticket_data["id"])
all_messages_path = os.path.join(output_dir, "all_messages.json")
save_json(messages_data, all_messages_path)
# Sauvegarde des pièces jointes
attachments_data = self.attachment_manager.get_ticket_attachments(ticket_data["id"], output_dir)
attachments_path = os.path.join(output_dir, "attachments_info.json")
save_json(attachments_data, attachments_path)
# Génération de structure.json
structure = {
"date_extraction": datetime.now().isoformat(),
"ticket_dir": output_dir,
"fichiers_json": [
"ticket_info.json",
"all_messages.json",
"attachments_info.json"
]
}
structure_path = os.path.join(output_dir, "structure.json")
save_json(structure, structure_path)
return {
"ticket_info": ticket_info_path,
"messages_file": all_messages_path,
"ticket_data_file": structure_path,
"attachments": attachments_path
}

View File

@ -1,26 +1,76 @@
from typing import Dict, Any, List
import os
import json
from datetime import datetime
from typing import Dict, Any
from .auth_manager import AuthManager
from .message_manager import MessageManager
from .attachment_manager import AttachmentManager
from .utils import save_json
class TicketManager:
def __init__(self, auth: AuthManager):
self.auth = auth
def __init__(self, auth_manager: AuthManager):
self.auth_manager = auth_manager
self.message_manager = MessageManager(auth_manager)
self.attachment_manager = AttachmentManager(auth_manager)
self.model_name = "project.task"
def get_ticket(self, ticket_id: int) -> Dict[str, Any]:
params = {
"model": self.model_name,
"method": "read",
"args": [[ticket_id]],
"kwargs": {"fields": ["id", "name", "description", "stage_id", "user_id", "create_date"]}
}
return self.auth._rpc_call("/web/dataset/call_kw", params)
def get_ticket_by_code(self, ticket_code: str) -> Dict[str, Any]:
params = {
"model": self.model_name,
"method": "search_read",
"args": [[["code", "=", ticket_code]], ["id", "name", "description", "stage_id", "user_id", "create_date"]],
"args": [[["code", "=", ticket_code]],
["id", "name", "description", "stage_id", "project_id", "partner_id",
"user_id", "date_start", "date_end", "create_date", "write_date",
"message_ids", "message_follower_ids", "attachment_ids", "timesheet_ids"]],
"kwargs": {"limit": 1}
}
result = self.auth._rpc_call("/web/dataset/call_kw", params)
return result[0] if isinstance(result, list) and result else {}
result = self.auth_manager.rpc_call("/web/dataset/call_kw", params)
if isinstance(result, list) and len(result) > 0:
return result[0]
else:
print(f"Aucun ticket trouvé avec le code {ticket_code}")
return {}
def extract_ticket_data(self, ticket_code: str, output_dir: str):
os.makedirs(output_dir, exist_ok=True)
ticket_data = self.get_ticket_by_code(ticket_code)
if not ticket_data or "id" not in ticket_data:
print(f"Erreur: Ticket non trouvé.")
return None
# Sauvegarder ticket_info.json
ticket_info_path = os.path.join(output_dir, "ticket_info.json")
save_json(ticket_data, ticket_info_path)
# Sauvegarde des messages
messages_data = self.message_manager.get_ticket_messages(ticket_data["id"])
all_messages_path = os.path.join(output_dir, "all_messages.json")
save_json(messages_data, all_messages_path)
# Sauvegarde des pièces jointes
attachments_data = self.attachment_manager.get_ticket_attachments(ticket_data["id"], output_dir)
attachments_path = os.path.join(output_dir, "attachments_info.json")
save_json(attachments_data, attachments_path)
# Génération de structure.json
structure = {
"date_extraction": datetime.now().isoformat(),
"ticket_dir": output_dir,
"fichiers_json": [
"ticket_info.json",
"all_messages.json",
"attachments_info.json"
]
}
structure_path = os.path.join(output_dir, "structure.json")
save_json(structure, structure_path)
return {
"ticket_info": ticket_info_path,
"messages_file": all_messages_path,
"ticket_data_file": structure_path,
"attachments": attachments_path
}