-
Notifications
You must be signed in to change notification settings - Fork 1
/
copy_files_bal_from202211to202411.py
72 lines (65 loc) · 2.6 KB
/
copy_files_bal_from202211to202411.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import argparse,os
import subprocess
from datetime import datetime as dt
from datetime import timedelta
parser = argparse.ArgumentParser(description="Algorithm launcher")
parser.add_argument('-sd', "--start_date", help="Start date (yyyy-mm-dd)")
parser.add_argument('-ed', "--end_date", help="End date (yyyy-mm-dd")
args = parser.parse_args()
def get_dates_from_arg():
start_date = None
end_date = None
if args.start_date:
try:
start_date = dt.strptime(args.start_date, '%Y-%m-%d')
except:
try:
tdelta = int(args.start_date)
start_date = dt.now() + timedelta(days=tdelta)
start_date = start_date.replace(hour=12, minute=0, second=0, microsecond=0)
except:
print(f'[ERROR] Start date {args.start_date} is not in the correct format: YYYY-mm-dd or integer')
if args.end_date:
try:
end_date = dt.strptime(args.end_date, '%Y-%m-%d')
except:
try:
tdelta = int(args.end_date)
end_date = dt.now() + timedelta(days=tdelta)
end_date = end_date.replace(hour=12, minute=0, second=0, microsecond=0)
except:
print(f'[ERROR] End date {args.end_date} is not in the correct format: YYYY-mm-dd or integer')
if args.start_date and not args.end_date:
end_date = start_date
return start_date, end_date
def main():
start_date, end_date = get_dates_from_arg()
if start_date is None or end_date is None:
return
dir_orig = '/dst04-data1/OC/OLCI/daily_v202311_bc'
dir_destiny = '/store3/OC/OLCI_BAL/dailyolci_202411'
date_here = start_date
while date_here<=end_date:
yyyy = date_here.strftime('%Y')
jjj = date_here.strftime('%j')
dir_orig_date = os.path.join(dir_orig,yyyy,jjj)
dir_destiny_date = os.path.join(dir_destiny,yyyy,jjj)
if os.path.exists(dir_orig_date):
if not os.path.exists(dir_destiny_date):
os.mkdir(dir_destiny_date)
cmd = f'chmod g+w {dir_destiny_date}'
print(cmd)
prog = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
out, err = prog.communicate()
if err:
print(err)
cmd = f'cp {dir_orig_date}/O{yyyy}{jjj}-rrs*bal-fr.nc {dir_destiny_date}'
print(cmd)
prog = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
out, err = prog.communicate()
if err:
print(err)
date_here = date_here + timedelta(hours=24)
if __name__ == '__main__':
print('[INFO] Started')
main()