From 07b4a2df0aa5c63909a530549c319ab6e85ab912 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Thu, 10 Mar 2016 05:16:15 +0100 Subject: [PATCH] [bde/compta] factorisation de getcursor() --- bde/compta/base.py | 1 + sum_transacs_by_categorie.py | 9 ++------- 2 files changed, 3 insertions(+), 7 deletions(-) create mode 120000 bde/compta/base.py diff --git a/bde/compta/base.py b/bde/compta/base.py new file mode 120000 index 0000000..9638ef5 --- /dev/null +++ b/bde/compta/base.py @@ -0,0 +1 @@ +../base.py \ No newline at end of file diff --git a/sum_transacs_by_categorie.py b/sum_transacs_by_categorie.py index d0c1e76..5359a62 100755 --- a/sum_transacs_by_categorie.py +++ b/sum_transacs_by_categorie.py @@ -9,13 +9,8 @@ Le script mange donc une liste de fichiers contenant une description par ligne. """ import sys -import psycopg2 -import psycopg2.extras -def getcursor(): - con = psycopg2.connect(database='note') - cur = con.cursor(cursor_factory=psycopg2.extras.DictCursor) - return con, cur +import base def get_sum(descriptions, debut, fin): """ @@ -32,7 +27,7 @@ def get_sum(descriptions, debut, fin): AND montant != 0 AND description = ANY (%(descriptions)s); """ - con, cur = getcursor() + con, cur = base.getcursor() cur.execute(req, {"debut" : debut + ' 00:00:00', "fin" : fin + ' 00:00:00', "descriptions" : descriptions}) s = cur.fetchone()["s"] or 0 return s -- 2.39.2