From fdfdd2302243c94e72bb320057276a323cd39031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Mon, 30 Mar 2015 17:18:54 +0200 Subject: [PATCH] =?UTF-8?q?Revert=20des=20deux=20commits=20pr=C3=A9c=C3=A9?= =?UTF-8?q?dents=20:=20c'=C3=A9tait=20un=20probl=C3=A8me=20de=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * tuple vs list dans les results. --- surveillance/deconnexion2.py | 50 ++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/surveillance/deconnexion2.py b/surveillance/deconnexion2.py index 0754fc78..94fba181 100755 --- a/surveillance/deconnexion2.py +++ b/surveillance/deconnexion2.py @@ -30,34 +30,11 @@ import gestion.mail as mail_module # Ça printe au lieu de faire bobo quand c'est à True DEBUG = False -LDAP = shortcuts.lc_ldap_admin() - EPOCH = pytz.utc.localize(datetime.datetime(1970, 1, 1)) TZ = pytz.timezone('Europe/Paris') DELTA = datetime.timedelta(0, upload.interval * 3600, 0) CUR_DATE = TZ.normalize(TZ.localize(datetime.datetime.now())) -# Connection à la base sql via pgsql -PGSQL = psycopg2.connect(database='filtrage', user='crans') -PGSQL.set_session(autocommit=True) -CURSEUR = PGSQL.cursor(cursor_factory=psycopg2.extras.DictCursor) - -# Avertis upload hard -REQUETE = "SELECT type, id FROM avertis_upload_hard WHERE date > now() - %(interval)s;" -CURSEUR.execute(REQUETE, { - 'interval': DELTA, -}) - -AVERTIS_UPLOAD_HARD = CURSEUR.fetchall() - -# Avertis upload soft -REQUETE = "SELECT type, id FROM avertis_upload_soft WHERE date > now() - %(interval)s" -CURSEUR.execute(REQUETE, { - 'interval': DELTA, -}) - -AVERTIS_UPLOAD_SOFT = CURSEUR.fetchall() - QUERY = """WITH machines_sans_doublon AS @@ -408,7 +385,7 @@ def single_check(eltype, elid, elupload, ldap, curseur): if elupload >= upload.hard: # L'adhérent a t il été blacklisté ? #################################### - if (eltype, elid) in AVERTIS_UPLOAD_HARD and not DEBUG: + if [eltype, int(elid)] in AVERTIS_UPLOAD_HARD and not DEBUG: return # Propriétaire issu de LDAP @@ -430,7 +407,7 @@ def single_check(eltype, elid, elupload, ldap, curseur): elif elupload >= upload.soft: # L'adhérent a t il été averti ou est déjà déco ? ################################################# - if ((eltype, elid) in AVERTIS_UPLOAD_SOFT or (eltype, elid) in AVERTIS_UPLOAD_HARD) and not DEBUG: + if ([eltype, int(elid)] in AVERTIS_UPLOAD_SOFT or [eltype, int(elid)] in AVERTIS_UPLOAD_HARD) and not DEBUG: return # Objets LDAP @@ -496,4 +473,27 @@ def reperage_chambre(mac): return "Inconnue", "Inconnue" if __name__ == "__main__": + LDAP = shortcuts.lc_ldap_admin() + + # Connection à la base sql via pgsql + PGSQL = psycopg2.connect(database='filtrage', user='crans') + PGSQL.set_session(autocommit=True) + CURSEUR = PGSQL.cursor(cursor_factory=psycopg2.extras.DictCursor) + + # Avertis upload hard + REQUETE = "SELECT type, id FROM avertis_upload_hard WHERE date > now() - %(interval)s;" + CURSEUR.execute(REQUETE, { + 'interval': DELTA, + }) + + AVERTIS_UPLOAD_HARD = CURSEUR.fetchall() + + # Avertis upload soft + REQUETE = "SELECT type, id FROM avertis_upload_soft WHERE date > now() - %(interval)s" + CURSEUR.execute(REQUETE, { + 'interval': DELTA, + }) + + AVERTIS_UPLOAD_SOFT = CURSEUR.fetchall() + main(CURSEUR, LDAP)