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):
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)
)
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]))