From: Vincent Le Gallic Date: Thu, 10 Mar 2016 04:16:15 +0000 (+0100) Subject: [bde/compta] factorisation de getcursor() X-Git-Url: http://gitweb.pimeys.fr/?p=scripts-20-100.git;a=commitdiff_plain;h=07b4a2df0aa5c63909a530549c319ab6e85ab912 [bde/compta] factorisation de getcursor() --- 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