iterate over specified date range

This commit is contained in:
Sundog 2023-08-25 11:49:39 -04:00
parent b730441f65
commit 4498feb07d
1 changed files with 14 additions and 2 deletions

View File

@ -13,6 +13,10 @@ to_date = datetime.date.today()
def main(): def main():
parse_config() parse_config()
for single_date in daterange(from_date, to_date):
if verbose:
print("Processing date", single_date)
build_day(single_date)
def parse_config(): def parse_config():
global mediadir, playlistdir, channel, verbose, from_date, to_date global mediadir, playlistdir, channel, verbose, from_date, to_date
@ -39,9 +43,9 @@ def parse_config():
if args.channel: if args.channel:
channel = args.channel channel = args.channel
if args.from_date: if args.from_date:
from_date = datetime.strptime(args.from_date, "%Y-%m-%d") from_date = datetime.datetime.strptime(args.from_date, "%Y-%m-%d").date()
if args.to_date: if args.to_date:
to_date = datetime.strptime(args.to_date, "%Y-%m-%d") to_date = datetime.datetime.strptime(args.to_date, "%Y-%m-%d").date()
if verbose: if verbose:
print("Arguments parsed, config:") print("Arguments parsed, config:")
@ -51,6 +55,14 @@ def parse_config():
print("from_date:", from_date) print("from_date:", from_date)
print("to_date:", to_date) print("to_date:", to_date)
def build_day(this_date):
# todo
pass
# generator function to yield single dates from a date range
def daterange(start_date, end_date):
for n in range(int((end_date - start_date).days) + 1): # adding 1 to make the range inclusive
yield start_date + datetime.timedelta(n)
if __name__ == "__main__": if __name__ == "__main__":
main() main()