Téléverser les fichiers vers "/"
This commit is contained in:
2
.env
Normal file
2
.env
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
VIRTUAL_ENV=C:\Program Files (x86)\wapt\
|
||||||
|
PYTHONPATH=C:\Program Files (x86)\wapt\
|
||||||
2
rocket.ini
Normal file
2
rocket.ini
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[rocket]
|
||||||
|
url= https://chat.comitari.fr/hooks/64d4d02760b38508f62a5bcb/ncKSYRiLM9oNXagK5c7G3KWX2qEzET3kbFFXKnNAhtfZQEQ9
|
||||||
125
setup.py
Normal file
125
setup.py
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from setuphelpers import *
|
||||||
|
import xmlrpc.client
|
||||||
|
import pickle
|
||||||
|
import os
|
||||||
|
from configparser import ConfigParser
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
url = 'https://odoo.comitari.fr'
|
||||||
|
db = 'comitari'
|
||||||
|
state_file = 'tickets_state.pkl'
|
||||||
|
api_key = "182534f9e754ce1016e86b86b4b5b47199659a6f"
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': f'Bearer {api_key}',
|
||||||
|
}
|
||||||
|
|
||||||
|
# Endpoint URL
|
||||||
|
endpoint = f'{url}/jsonrpc'
|
||||||
|
|
||||||
|
# Payload pour récupérer tous les tickets
|
||||||
|
payload = {
|
||||||
|
'jsonrpc': '2.0',
|
||||||
|
'method': 'call',
|
||||||
|
'params': {
|
||||||
|
'model': 'helpdesk.ticket',
|
||||||
|
'method': 'search_read',
|
||||||
|
'args': [[], ['id', 'write_date']],
|
||||||
|
},
|
||||||
|
'id': 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
def install():
|
||||||
|
|
||||||
|
plugin_inifile = makepath(WAPT.private_dir, "rocket.ini")
|
||||||
|
|
||||||
|
if not isfile(plugin_inifile):
|
||||||
|
filecopyto("rocket.ini", WAPT.private_dir)
|
||||||
|
|
||||||
|
def audit():
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Récupération de l'état actuel de tous les tickets
|
||||||
|
response = requests.post(endpoint, json=payload, headers=headers)
|
||||||
|
response.raise_for_status() # Vérifie si la requête a réussi
|
||||||
|
response_data = response.json()
|
||||||
|
|
||||||
|
# Vérifie si 'result' est présent dans la réponse
|
||||||
|
if 'result' in response_data:
|
||||||
|
tickets = response_data['result']
|
||||||
|
else:
|
||||||
|
print("Erreur: La clé 'result' n'est pas présente dans la réponse.")
|
||||||
|
print("Réponse complète:", response_data)
|
||||||
|
tickets = []
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
print(f"Erreur lors de la requête: {e}")
|
||||||
|
tickets = []
|
||||||
|
|
||||||
|
# Vérification si un état précédent existe
|
||||||
|
if os.path.exists(state_file):
|
||||||
|
with open(state_file, 'rb') as f:
|
||||||
|
previous_tickets_state = pickle.load(f)
|
||||||
|
else:
|
||||||
|
previous_tickets_state = {}
|
||||||
|
|
||||||
|
|
||||||
|
# Comparaison et affichage des résultats
|
||||||
|
tickets_updated = []
|
||||||
|
for ticket in tickets:
|
||||||
|
ticket_id = ticket['id']
|
||||||
|
ticket_write_date = ticket['write_date']
|
||||||
|
|
||||||
|
if ticket_id in previous_tickets_state:
|
||||||
|
if ticket_write_date != previous_tickets_state[ticket_id]:
|
||||||
|
tickets_updated.auppend(ticket_id)
|
||||||
|
else:
|
||||||
|
tickets_updated.append(ticket_id)
|
||||||
|
|
||||||
|
if tickets_updated:
|
||||||
|
message = f"Les tickets suivants ont été mis à jour depuis la dernière vérification : {tickets_updated}"
|
||||||
|
send_to_rocket(message)
|
||||||
|
|
||||||
|
else:
|
||||||
|
message = "Aucun ticket n'a été mis à jour depuis la dernière vérification."
|
||||||
|
send_to_rocket(message)
|
||||||
|
# Sauvegarde de l'état actuel pour la prochaine exécution
|
||||||
|
current_tickets_state = {ticket['id']: ticket['write_date'] for ticket in tickets}
|
||||||
|
with open(state_file, 'wb') as f:
|
||||||
|
pickle.dump(current_tickets_state, f)
|
||||||
|
return "OK"
|
||||||
|
|
||||||
|
|
||||||
|
def send_to_rocket(message_text, attachments=None):
|
||||||
|
"""
|
||||||
|
Envoie un message à Rocket.Chat via un webhook.
|
||||||
|
|
||||||
|
:param message_text: Texte du message à envoyer
|
||||||
|
:param attachments: Liste de pièces jointes (facultatif)
|
||||||
|
"""
|
||||||
|
smtp_inifile = makepath(WAPT.private_dir, "rocket.ini")
|
||||||
|
conf_wapt = ConfigParser()
|
||||||
|
conf_wapt.read(smtp_inifile)
|
||||||
|
|
||||||
|
webhook_url = conf_wapt.get("rocket", "url")
|
||||||
|
|
||||||
|
# Construire le message
|
||||||
|
|
||||||
|
message = {
|
||||||
|
'text': message_text
|
||||||
|
}
|
||||||
|
if attachments:
|
||||||
|
message['attachments'] = attachments
|
||||||
|
|
||||||
|
# Envoyer la requête POST
|
||||||
|
response = requests.post(webhook_url, data=json.dumps(message), headers={'Content-Type': 'application/json'})
|
||||||
|
|
||||||
|
# Vérifier la réponse
|
||||||
|
if response.status_code == 200:
|
||||||
|
print('Message envoyé avec succès.')
|
||||||
|
else:
|
||||||
|
print(f'Échec de l\'envoi du message. Statut de la réponse : {response.status_code}')
|
||||||
|
print(f'Erreur : {response.text}')
|
||||||
|
|
||||||
1
tickets_state.pkl
Normal file
1
tickets_state.pkl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>}<7D>.
|
||||||
Reference in New Issue
Block a user