Commit 29c2d5c9 authored by JonathanMM's avatar JonathanMM

Creation du script de nettoyage

parent 705eb7c8
import datetime
from nettoyageLib import nettoyerInstantanne, nettoyerConso
date = datetime.datetime.today() - datetime.timedelta(days=2)
dateLimite = date.replace(microsecond = 0, second = 0, minute=0, hour=0)
nettoyerInstantanne(dateLimite)
nettoyerConso(dateLimite, "duree = 5 OR duree = 15")
dateHuitJours = datetime.datetime.today() - datetime.timedelta(days=8)
dateLimiteHuitJours = dateHuitJours.replace(microsecond = 0, second = 0, minute=0, hour=0)
nettoyerConso(dateLimiteHuitJours, "duree = 60")
\ No newline at end of file
import pymysql
from config import getMysqlConnection
def nettoyerInstantanne(date):
dateStr = date.strftime("%Y-%m-%d %H:%M:%S")
mysql = getMysqlConnection()
requete = mysql.cursor()
requete.execute('DELETE FROM status WHERE idConso IN ( \
SELECT id FROM statusConso \
WHERE date < "'+dateStr+'")')
requete = mysql.cursor()
requete.execute('DELETE FROM statusConso WHERE date < "'+dateStr+'"')
def nettoyerConso(date, filtre):
dateStr = date.strftime("%Y-%m-%d %H:%M:%S")
mysql = getMysqlConnection()
requete = mysql.cursor()
requete.execute('DELETE FROM resumeStatus WHERE date < "'+dateStr+'" AND ('+filtre+')')
requete = mysql.cursor()
requete.execute('DELETE FROM resumeConso WHERE date < "'+dateStr+'" AND ('+filtre+')')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment