@nunzio
> assurdo ci sia motivo di NON usare una libreria standard di python in uno script python
No, possono esserci degli scenari in cui non è davvero possibile...
@OP
> Ne sono venuta a capo.
Non ne sei venuta a capo...
Ah! ... beh, alla mia età la mente è "rigida" e manca di immaginazione, comunque mi ha intrigato pormi la domanda "al posto dello OP come risolverei?"
Facile, dato l'algoritmo indicato da @Ric, tutto sommato uno dei più logici, ho immaginato un "DateStepper" (non so se è "inglese" ma suona bene

) e ci ho giochicchiato un pochino, non è un gran che (giusto un minimo) ma lo posto, sai mai possa servire
# -*- coding: utf-8 -*-
class DateStepper:
def __init__(self, year, month, day, step=1):
self._days = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
self.year = year
self.month = month
self.day = day
self._evaluate_year()
self.step = step
if self.step >= 0:
self.passo = 1
else:
self.passo = -1
self.sep = '-'
def _evaluate_year(self):
if not self.year % 400:
self._days[1] = 29
elif not self.year % 4:
self._days[1] = 29
else:
self._days[1] = 28
def __iter__(self):
return self
def __next__(self):
for i in range(abs(self.step)):
self.day += self.passo
if self.day > self._days[self.month - 1]:
self.day = 1
self.month += 1
if self.month > 12:
self.month = 1
self.year += 1
self._evaluate_year()
elif self.day < 1:
self.month -= 1
if self.month < 1:
self.month = 12
self.year -= 1
self.evaluate_year()
self.day = self._days[self.month -1]
return self
def __eq__(self, o_obj):
return ((self.year, self.month, self.day) == (o_obj.year, o_obj.month, o_obj.day))
def __lt__(self, o_obj):
return ((self.year, self.month, self.day) < (o_obj.year, o_obj.month, o_obj.day))
def __repr__(self):
return self.sep.join(('%04d' % self.year, '%02d' % self.month, '%02d' % self.day))
def get_urls(aqp, start_d, limit_d):
urls = []
while start_d < limit_d:
url = 'url' + aqp + '/csv?start_date=' + str(start_d)
next(start_d)
url += '&end_date=' + str(start_d)
urls.append(url)
return urls
if __name__ == '__main__':
numAQP = input("Inserisci il numero della AQP:")
mese_iniziale = input("Inserisci il mese iniziale:")
anno_iniziale = input("Inserisci anno iniziale:")
start_date = DateStepper(int(anno_iniziale), int(mese_iniziale), 1)
mese_finale = input("Inserisci il mese_finale:")
anno_finale = input("Inserisci anno_finale:")
limit_date = DateStepper(int(anno_finale), int(mese_finale)+1, 1, -1)
my_urls = get_urls(numAQP, start_date, next(limit_date))
for u in my_urls:
print(u)
P.S. - mi son divertito a farlo andare avanti ed indietro "nel tempo", i bisestili li becca ma non vuole essere niente, è solo un giocattolo da usare se proprio "non si può"
