From 7630720dd491fa53093743e683d4e05f22d03afd Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Thu, 18 Feb 2016 11:14:20 +0100 Subject: [PATCH] On fournit la date de fin MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Comme ça, plus de problème si on fait un bilan un 1er du mois ça marche pour tout, plus de hack. Et ça permet de faire un bilan sur légèrement plus de 365 jours si on veut --- sum_transacs_by_categorie.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/sum_transacs_by_categorie.py b/sum_transacs_by_categorie.py index 900ed80..39dfb67 100755 --- a/sum_transacs_by_categorie.py +++ b/sum_transacs_by_categorie.py @@ -37,16 +37,23 @@ def get_sum(descriptions, debut, fin): s = cur.fetchone()["s"] or 0 return s -def get_dates(y, m, d): +def get_dates(y, m, d, yf, mf, df): """ Donne les dates de découpage de ``d``/``m``/``y`` à ``d-1``/``m``/``y+1``. """ - dates = ["%s-%s-%s" % (y, m, d)] - for i in range(m + 1, 13): - dates.append("%s-%s-01" % (y, i)) - for i in range(1, m): - dates.append("%s-%s-01" % (y + 1, i)) - dates.append("%s-%s-%s" % (y + 1, m, d - 1)) + dates = ["%d-%02d-%02d" % (y, m, d)] + m += 1 + if m == 13: + m = 1 + y += 1 + while (y, m) <= (yf, mf): + dates.append("%d-%02d-01" % (y, m)) + m += 1 + if m == 13: + m = 1 + y += 1 + # On a atteint le dernier mois + dates.append("%d-%02d-%02d" % (yf, mf, df)) return dates def get_year_sums(dates, filename): @@ -65,7 +72,8 @@ if __name__ == "__main__": filenames = sys.argv[1:] print filenames y, m, d = 2015, 2, 16 - dates = get_dates(y, m, d) + yf, mf, df = 2016, 2, 18 + dates = get_dates(y, m, d, yf, mf, df) ys = {} for fn in filenames: ys[fn] = get_year_sums(dates, fn) @@ -79,7 +87,7 @@ if __name__ == "__main__": ) print "totaux" - print "%s-%s-%s\t %s-%s-%s\t %s" % (y, m, d, y+1, m, d-1, + print "%s-%s-%s\t %s-%s-%s\t %s" % (y, m, d, yf, mf, df, "\t".join([str(sum(ys[fn])) for fn in filenames]),) print "total" print str(sum([sum(ys[fn]) for fn in filenames])) -- 2.39.2