From: Vincent Le Gallic Date: Sun, 15 Feb 2015 15:37:54 +0000 (+0100) Subject: [depenses.py] Utilisable en l'important X-Git-Url: http://gitweb.pimeys.fr/?a=commitdiff_plain;h=84fd0efcfe841c786055ad912edec74fad0d2bfc;p=scripts-20-100.git [depenses.py] Utilisable en l'important --- diff --git a/bde/stats/depenses.py b/bde/stats/depenses.py index 248411b..b0ca825 100755 --- a/bde/stats/depenses.py +++ b/bde/stats/depenses.py @@ -49,16 +49,21 @@ def get_depenses(idbde): con, cur = get_cursor() cur.execute(create_temp_table, {"idbde" : idbde}) cur.execute(display_all) - l = cur.fetchall() + all = cur.fetchall() + cur.execute(display_sum) + tot = cur.fetchall()[0] + return (all, tot) + +def display_depenses(all, tot): + """Pretty-printing des résultats.""" print "annee\tdepenses\tgains" - for li in l: + for li in all: li = [int(li[0]), li[1], li[2]] print "%s\t%s\t\t%s" % tuple(li) - cur.execute(display_sum) - l = cur.fetchall() print "\nTotal :\n\tdepenses\tgains" - print "\t%s\t\t%s" % tuple(l[0]) + print "\t%s\t\t%s" % tuple(tot) if __name__ == "__main__": idbde = int(sys.argv[1]) - get_depenses(idbde) + all, tot = get_depenses(idbde) + display_depenses(all, tot)