Commit b920378a authored by Gaetano Raffaele's avatar Gaetano Raffaele
Browse files

ENH: added app for date file generation.

parent 2dfc9653
No related merge requests found
Showing with 24 additions and 0 deletions
+24 -0
from datetime import datetime, timedelta
def periodic_date_generator(filename, start_date, end_date, step):
start_date = start_date.split('-')
start_date = datetime(int(start_date[0]),int(start_date[1]),int(start_date[2]))
end_date = end_date.split('-')
end_date = datetime(int(end_date[0]),int(end_date[1]),int(end_date[2]))
d = start_date
step = timedelta(days=step)
with open(filename, 'w') as f:
while d < end_date :
f.write(d.strftime('%Y%m%d')+'\n')
d += step
import sys import sys
import argparse import argparse
from Common.timetools import periodic_date_generator
from Workflows.basic import basic from Workflows.basic import basic
from Workflows.operations import * from Workflows.operations import *
...@@ -80,6 +81,13 @@ def main(args): ...@@ -80,6 +81,13 @@ def main(args):
chain.add_argument("--runlevel", type=int, default=1, help="Starting step of the chain to process.") chain.add_argument("--runlevel", type=int, default=1, help="Starting step of the chain to process.")
chain.add_argument("--single_step", action="store_true", help="Stop after a single step is processed.") chain.add_argument("--single_step", action="store_true", help="Stop after a single step is processed.")
dategen = subpar.add_parser("gen_date_file", help="Generate an output date file for classic gapfilling.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
dategen.add_argument("output_file", type=str, help="Path to the output date file.")
dategen.add_argument("start_date", type=str, help="Start date in YYYY-MM-DD format.")
dategen.add_argument("end_date", type=str, help="End date in YYYY-MM-DD format.")
dategen.add_argument("step", type=int, help="Number of days between two dates.")
if len(args) == 1: if len(args) == 1:
parser.print_help() parser.print_help()
sys.exit(0) sys.exit(0)
...@@ -115,6 +123,9 @@ def main(args): ...@@ -115,6 +123,9 @@ def main(args):
else: else:
raise ValueError('Workflow not implemented.') raise ValueError('Workflow not implemented.')
if arg.cmd == "gen_date_file":
periodic_date_generator(arg.output_file, arg.start_date, arg.end_date, arg.step)
return 0 return 0
if __name__ == "__main__": if __name__ == "__main__":
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment