Untitled
unknown
plain_text
2 years ago
1.6 kB
10
Indexable
import argparse
import os
import subprocess
from datetime import datetime, timedelta
def run_script(date, output_directory):
# Construct the output filename based on the given date
output_fname = os.path.join(output_directory, f"output_{date}.csv")
# Call your script using subprocess
subprocess.run(["my_script", "--date", date, "--output_fname", output_fname])
def main():
parser = argparse.ArgumentParser(description="Wrapper for my_script")
parser.add_argument("--start_date", type=str, required=True, help="Start date in YYYYMMDD format")
parser.add_argument("--end_date", type=str, required=True, help="End date in YYYYMMDD format")
parser.add_argument("--output_directory", type=str, required=True, help="Directory to store output files")
args = parser.parse_args()
# Convert the provided dates to datetime objects for easy manipulation
start_date = datetime.strptime(args.start_date, '%Y%m%d')
end_date = datetime.strptime(args.end_date, '%Y%m%d')
# Create the output directory if it doesn't exist
os.makedirs(args.output_directory, exist_ok=True)
# Loop through each date, skip weekends, and call the script
current_date = start_date
while current_date <= end_date:
# Check if the current_date is not a weekend (5 = Saturday, 6 = Sunday)
if current_date.weekday() not in [5, 6]:
run_script(current_date.strftime('%Y%m%d'), args.output_directory)
current_date += timedelta(days=1)
if __name__ == "__main__":
main()
Editor is loading...