Resetting utils subtree.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import datetime
|
||||
import argparse
|
||||
|
||||
# Get the range from the console:
|
||||
parser = argparse.ArgumentParser(description = "Generates comma-separated date strings in a given range.")
|
||||
parser.add_argument(
|
||||
"-s", "--start-date",
|
||||
dest = "start_date",
|
||||
type = str,
|
||||
help = "The starting date of the range in 'YYYY-MM-DD' format."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-e", "--end-date",
|
||||
dest = "end_date",
|
||||
type = str,
|
||||
help = "The ending date of the range in 'YYYY-MM-DD' format."
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# Convert the date strings into datetime objects:
|
||||
start_dt = datetime.datetime.strptime(args.start_date, "%Y-%m-%d")
|
||||
end_dt = datetime.datetime.strptime(args.end_date, "%Y-%m-%d")
|
||||
|
||||
# Check if the end date is after the start date:
|
||||
if end_dt < start_dt: raise ValueError("End date must be after the start date.")
|
||||
|
||||
# Make the list of dates:
|
||||
date_list = []
|
||||
while True:
|
||||
this_dt = start_dt + datetime.timedelta(days = len(date_list))
|
||||
date_list.append(this_dt.strftime("%Y-%m-%d"))
|
||||
if this_dt >= end_dt: break
|
||||
|
||||
# Print the list out as one string:
|
||||
print("HERE IS THE DATE STRING:")
|
||||
print(",".join(date_list))
|
||||
Reference in New Issue
Block a user