mirror of
https://github.com/Ladebeze66/llm_ticket3.git
synced 2025-12-16 03:57:47 +01:00
14:31extract
This commit is contained in:
parent
7fa35fe108
commit
be2c9e8a6c
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
@ -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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -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"
|
|
||||||
}
|
|
||||||
Binary file not shown.
75
utils/data_extractor.py
Normal file
75
utils/data_extractor.py
Normal 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
|
||||||
|
}
|
||||||
@ -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 .auth_manager import AuthManager
|
||||||
|
from .message_manager import MessageManager
|
||||||
|
from .attachment_manager import AttachmentManager
|
||||||
|
from .utils import save_json
|
||||||
|
|
||||||
class TicketManager:
|
class TicketManager:
|
||||||
def __init__(self, auth: AuthManager):
|
def __init__(self, auth_manager: AuthManager):
|
||||||
self.auth = auth
|
self.auth_manager = auth_manager
|
||||||
|
self.message_manager = MessageManager(auth_manager)
|
||||||
|
self.attachment_manager = AttachmentManager(auth_manager)
|
||||||
self.model_name = "project.task"
|
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]:
|
def get_ticket_by_code(self, ticket_code: str) -> Dict[str, Any]:
|
||||||
params = {
|
params = {
|
||||||
"model": self.model_name,
|
"model": self.model_name,
|
||||||
"method": "search_read",
|
"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}
|
"kwargs": {"limit": 1}
|
||||||
}
|
}
|
||||||
result = self.auth._rpc_call("/web/dataset/call_kw", params)
|
result = self.auth_manager.rpc_call("/web/dataset/call_kw", params)
|
||||||
return result[0] if isinstance(result, list) and result else {}
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user