#!/usr/bin/env python
# -*- coding: utf8 -*-
# Usage 'date_gen.py from_date [to_date]'
# Ce script utilisera la date d'aujourd'hui si "to_date" n'est pas précisé
import re, sys, calendar
from datetime import date, time, datetime

from_date = sys.argv[1]

reg = {}
reg['date'] = '^([0-9]{4})-([0-9]{2})-([0-9]{2})$'

if re.search(reg['date'], from_date) is not None:
  m = re.search(reg['date'], from_date)
  from_date = datetime(int(m.group(1)), int(m.group(2)), int(m.group(3))).date()
else:
  sys.exit('Le 1er argument doit être la date de début (de la forme 2016-04-13)')

try:
  to_date = sys.argv[2]
  if re.search(reg['date'], to_date) is not None:
    m = re.search(reg['date'], to_date)
    to_date = datetime(int(m.group(1)), int(m.group(2)), int(m.group(3))).date()
  else:
    sys.exit('Le 2nd argument (optionnel) doit être la date de fin (de la forme 2016-04-13)')
except IndexError:
  to_date = datetime.now().date()

cal = calendar.Calendar()

for year in range(from_date.year, to_date.year+1):

  # 1ère année
  if from_date.year == year:
    start_month = from_date.month
  else:
    start_month = 1

  # dernière année
  if to_date.year == year:
    stop_month = to_date.month
  else:
    stop_month = 12

  for month in range(start_month, stop_month+1):

    for day in cal.itermonthdates(year, month):

      if day >= from_date and day.month == month and day <= to_date:
        print(day)

@@ -173,18 +173,8 @@
  sys
-, calendar
 %0Afro
@@ -205,68 +205,36 @@
 time
-, datetime%0A%0Afrom_date = sys.argv%5B1%5D%0A%0Areg = %7B%7D%0Areg%5B'date'%5D = 
+delta%0A%0Are_date = re.compile(
 '%5E(%5B
@@ -269,58 +269,63 @@
 %7D)$'
+)
 %0A%0Aif 
-re.search(reg%5B'date'%5D, from_date) is not None
+len(sys.argv) %3E 1 and re_date.search(sys.argv%5B1%5D)
 :%0A  
@@ -326,32 +326,37 @@
 %5D):%0A  m = re
+_date
 .search(
 reg%5B'date'%5D,
@@ -347,30 +347,19 @@
 rch(
-reg%5B'date'%5D, from_date
+sys.argv%5B1%5D
 )%0A  
@@ -366,36 +366,32 @@
 from_date = date
-time
 (int(m.group(1))
@@ -425,23 +425,16 @@
 oup(3)))
-.date()
 %0Aelse:%0A 
@@ -551,24 +551,29 @@
 %0A  if re
+_date
 .search(
 reg%5B'dat
@@ -568,41 +568,16 @@
 rch(
-reg%5B'date'%5D, to_date) is not None
+to_date)
 :%0A  
@@ -584,24 +584,29 @@
   m = re
+_date
 .search(
 reg%5B'dat
@@ -601,21 +601,8 @@
 rch(
-reg%5B'date'%5D, 
 to_d
@@ -624,20 +624,16 @@
 e = date
-time
 (int(m.g
@@ -675,23 +675,16 @@
 oup(3)))
-.date()
 %0A  else:
@@ -817,502 +817,190 @@
 date
-time.now().date()%0A%0Acal = calendar.Calendar()%0A%0Afor year in range(from_date.year, to_date.year+1):%0A%0A  # 1%C3%A8re ann%C3%A9e%0A  if from_date.year == year:%0A    start_month = from_date.month%0A  else:%0A    start_month = 1%0A%0A  # derni%C3%A8re ann%C3%A9e%0A  if to_date.year == year:%0A    stop_month = to_date.month%0A  else:%0A    stop_month = 12%0A%0A  for month in range(start_month, stop_month+1):%0A%0A    for day in cal.itermonthdates(year, month):%0A%0A      if day %3E= from_date and day.month == month and day %3C= to_date:%0A        print
+.today()%0A%0Aif to_date %3C from_date:%0A  sys.exit('La date de d%C3%A9but doit %C3%AAtre ant%C3%A9rieure %C3%A0 la date de fin')%0A%0Adate = from_date%0Awhile date %3C= to_date:%0A  print(date)%0A  date += timedelta
 (day
+s=1
 )%0A

simplify code