1
1
##############################################################################
2
2
#
3
3
# Copyright (c) His Majesty the King in Right of Canada, as
4
- # represented by the Minister of Natural Resources, 2023
4
+ # represented by the Minister of Natural Resources, 2025
5
5
#
6
6
# Licensed under the MIT license
7
7
# (see LICENSE or <http://opensource.org/licenses/MIT>) All files in the
17
17
import textwrap
18
18
from colorama import Fore , Back , Style
19
19
from tqdm .auto import tqdm
20
- import datetime
20
+ from datetime import datetime , timezone
21
21
import dateutil .parser as util_parser
22
22
# import dateparser
23
23
import json
@@ -169,6 +169,8 @@ def __init__(self, **kwargs):
169
169
170
170
self .csv_unique = ['recordid' , 'record id' , 'sequence id' ]
171
171
172
+ self .time_words = ['hour' , 'day' , 'week' , 'month' , 'year' ]
173
+
172
174
self .sat_coll_mapping = {'COSMOS-Skymed' : ['COSMO-SkyMed1' ],
173
175
'NAPL' : ['NAPL' ],
174
176
'sgap' : ['SGBAirPhotos' ],
@@ -288,9 +290,9 @@ def _parse_dates(self, in_dates):
288
290
if in_dates is None or in_dates == '' :
289
291
return ''
290
292
291
- time_words = ['hour' , 'day' , 'week' , 'month' , 'year' ]
293
+ # time_words = ['hour', 'day', 'week', 'month', 'year']
292
294
293
- if any (word in in_dates for word in time_words ):
295
+ if any (word in in_dates for word in self . time_words ):
294
296
dates = [in_dates ]
295
297
else :
296
298
@@ -616,6 +618,10 @@ def _print_results(self, orders):
616
618
order_id = item_info .get_metadata ('orderId' )
617
619
orderitem_id = item_info .get_metadata ('itemId' )
618
620
dests = item_info .get_metadata ('downloadPaths' )
621
+ if dests is None :
622
+ # print(f"Skipping Image with Record Id: {rec_id}")
623
+ continue
624
+
619
625
for d in dests :
620
626
loc_dest = d ['local_destination' ]
621
627
src_url = d ['url' ]
@@ -928,7 +934,7 @@ def cleanup_folders(self):
928
934
self .download_path , '*.*' ))
929
935
930
936
for f in downloads_files :
931
- file_date = datetime .datetime . fromtimestamp (os .path .getmtime (f ))
937
+ file_date = datetime .fromtimestamp (os .path .getmtime (f ))
932
938
933
939
if file_date < downloads_start :
934
940
# # print("The file %s will be deleted." % r)
@@ -1983,7 +1989,7 @@ def _finish_process(self, orders=None, in_imgs=None):
1983
1989
1984
1990
self .export_results ()
1985
1991
1986
- end_time = datetime .datetime . now ()
1992
+ end_time = datetime .now ()
1987
1993
end_str = end_time .strftime ("%Y-%m-%d %H:%M:%S" )
1988
1994
1989
1995
self .logger .info (f"End time: { end_str } " )
@@ -1996,7 +2002,7 @@ def _set_result_fn(self):
1996
2002
:rtype: str
1997
2003
"""
1998
2004
1999
- start_time = datetime .datetime . now ()
2005
+ start_time = datetime .now ()
2000
2006
start_str = start_time .strftime ("%Y-%m-%d %H:%M:%S" )
2001
2007
self .fn_str = start_time .strftime ("%Y%m%d_%H%M%S" )
2002
2008
@@ -2089,7 +2095,11 @@ def search_order_download(self, params):
2089
2095
2090
2096
# Print results info
2091
2097
msg = f"{ query_imgs .count ()} unique images returned from search " \
2092
- f"results.\n \n "
2098
+ f"results:\n \n "
2099
+ if query_imgs .count () <= 20 :
2100
+ msg += f"Record Ids: { ', ' .join (query_imgs .get_ids ())} "
2101
+ else :
2102
+ msg += "Check the results file for Record Ids."
2093
2103
self .print_footer ('Query Results' , msg )
2094
2104
2095
2105
if no_order :
@@ -2494,9 +2504,25 @@ def download_available(self, params):
2494
2504
2495
2505
self .logger .info (f"Process start time: { start_str } " )
2496
2506
2507
+ dtstart = None
2508
+ dtend = None
2509
+ if self .order_check_date :
2510
+ dtstart = self .order_check_date
2511
+ dtend = datetime .now (timezone .utc ).strftime ('%Y-%m-%dT%H:%M:%S' )
2512
+
2513
+ if any (word in dtstart for word in self .time_words ):
2514
+ print (f"\n Getting orders from the last { dtstart } "
2515
+ f"(from entry RAPI.order_check_date set in the "
2516
+ f"configuration file).\n " )
2517
+ else :
2518
+ print (f"\n Getting orders since { dtstart } "
2519
+ f"(from entry RAPI.order_check_date set in the "
2520
+ f"configuration file).\n " )
2521
+
2497
2522
################################################
2498
2523
# Get Existing Orders
2499
2524
################################################
2525
+ orders = image .OrderList (self )
2500
2526
if self .order_items is not None and not self .order_items == '' :
2501
2527
# Parse orders and order items
2502
2528
oi_split = self .order_items .split ('|' )
@@ -2512,7 +2538,6 @@ def download_available(self, params):
2512
2538
item_ids += ids
2513
2539
2514
2540
# orders = []
2515
- orders = image .OrderList (self )
2516
2541
for id in order_ids :
2517
2542
order = self .eodms_rapi .get_order (id )
2518
2543
if order is not None :
@@ -2529,15 +2554,17 @@ def download_available(self, params):
2529
2554
2530
2555
elif self .max_downloads is not None and not self .max_downloads == '' :
2531
2556
ord_res = self .eodms_rapi .get_orders (max_orders = self .max_downloads ,
2557
+ dtstart = dtstart , dtend = dtend ,
2532
2558
status = 'AVAILABLE_FOR_DOWNLOAD' )
2533
2559
imgs = self .get_image_from_order (ord_res )
2534
2560
orders .ingest_results (ord_res , imgs )
2535
2561
else :
2536
2562
max_orders = 250
2537
- orders = None
2563
+ ord_res = None
2538
2564
# Cycle through until orders have been returned
2539
- while orders is None and max_orders > 0 :
2565
+ while ord_res is None and max_orders > 0 :
2540
2566
ord_res = self .eodms_rapi .get_orders (max_orders = max_orders ,
2567
+ dtstart = dtstart , dtend = dtend ,
2541
2568
status = 'AVAILABLE_FOR_DOWNLOAD' )
2542
2569
imgs = self .get_image_from_order (ord_res )
2543
2570
orders .ingest_results (ord_res , imgs )
@@ -2551,7 +2578,7 @@ def download_available(self, params):
2551
2578
self .exit_cli (1 )
2552
2579
2553
2580
msg = f"Number of order items with status " \
2554
- f"AVAILABLE_FOR_DOWNLOAD: { orders .count ()} "
2581
+ f"AVAILABLE_FOR_DOWNLOAD: { orders .count_items ()} "
2555
2582
print (f"\n { msg } " )
2556
2583
self .logger .info (msg )
2557
2584
0 commit comments