Skip to content

Commit 3d1761c

Browse files
authored
Merge pull request #62 from eodms-sgdot/development
Development
2 parents 0e80cd6 + 3ce5b38 commit 3d1761c

File tree

6 files changed

+46
-40
lines changed

6 files changed

+46
-40
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MIT License
22

33
Copyright (c) His Majesty the King in Right of Canada,
4-
as represented by the Minister of Natural Resources, 2023.
4+
as represented by the Minister of Natural Resources, 2025.
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,3 @@ If you have any questions or require support, please contact the EODMS Support T
124124
## License
125125

126126
MIT License
127-
128-
Copyright (c) His Majesty the King in Right of Canada, as
129-
represented by the Minister of Natural Resources, 2024
130-
131-
Permission is hereby granted, free of charge, to any person obtaining a
132-
copy of this software and associated documentation files (the "Software"),
133-
to deal in the Software without restriction, including without limitation
134-
the rights to use, copy, modify, merge, publish, distribute, sublicense,
135-
and/or sell copies of the Software, and to permit persons to whom the
136-
Software is furnished to do so, subject to the following conditions:
137-
138-
The above copyright notice and this permission notice shall be included in
139-
all copies or substantial portions of the Software.
140-
141-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
142-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
143-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
144-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
145-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
146-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
147-
DEALINGS IN THE SOFTWARE.

eodms_cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
##############################################################################
22
#
33
# Copyright (c) His Majesty the King in Right of Canada, as
4-
# represented by the Minister of Natural Resources, 2024
4+
# represented by the Minister of Natural Resources, 2025
55
#
66
# Licensed under the MIT license
77
# (see LICENSE or <http://opensource.org/licenses/MIT>) All files in the
@@ -17,7 +17,7 @@
1717
__license__ = 'MIT License'
1818
__description__ = 'Script used to search, order and download imagery from ' \
1919
'the EODMS using the REST API (RAPI) service.'
20-
__version__ = '3.6.2'
20+
__version__ = '3.6.3'
2121
__maintainer__ = 'Kevin Ballantyne'
2222
__email__ = 'eodms-sgdot@nrcan-rncan.gc.ca'
2323

@@ -2143,9 +2143,9 @@ def cli(username, password, input_val, collections, process, filters, dates,
21432143

21442144
eod.eodms_rapi.close_session()
21452145

2146-
print("\nProcess complete.")
2146+
# print("\nProcess complete.")
21472147

2148-
eod.print_support()
2148+
# eod.print_support()
21492149

21502150
eod.exit_cli()
21512151

scripts/config_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
##############################################################################
22
#
33
# 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
55
#
66
# Licensed under the MIT license
77
# (see LICENSE or <http://opensource.org/licenses/MIT>) All files in the

scripts/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
##############################################################################
22
#
33
# 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
55
#
66
# Licensed under the MIT license
77
# (see LICENSE or <http://opensource.org/licenses/MIT>) All files in the

scripts/utils.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
##############################################################################
22
#
33
# 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
55
#
66
# Licensed under the MIT license
77
# (see LICENSE or <http://opensource.org/licenses/MIT>) All files in the
@@ -17,7 +17,7 @@
1717
import textwrap
1818
from colorama import Fore, Back, Style
1919
from tqdm.auto import tqdm
20-
import datetime
20+
from datetime import datetime, timezone
2121
import dateutil.parser as util_parser
2222
# import dateparser
2323
import json
@@ -169,6 +169,8 @@ def __init__(self, **kwargs):
169169

170170
self.csv_unique = ['recordid', 'record id', 'sequence id']
171171

172+
self.time_words = ['hour', 'day', 'week', 'month', 'year']
173+
172174
self.sat_coll_mapping = {'COSMOS-Skymed': ['COSMO-SkyMed1'],
173175
'NAPL': ['NAPL'],
174176
'sgap': ['SGBAirPhotos'],
@@ -288,9 +290,9 @@ def _parse_dates(self, in_dates):
288290
if in_dates is None or in_dates == '':
289291
return ''
290292

291-
time_words = ['hour', 'day', 'week', 'month', 'year']
293+
# time_words = ['hour', 'day', 'week', 'month', 'year']
292294

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):
294296
dates = [in_dates]
295297
else:
296298

@@ -616,6 +618,10 @@ def _print_results(self, orders):
616618
order_id = item_info.get_metadata('orderId')
617619
orderitem_id = item_info.get_metadata('itemId')
618620
dests = item_info.get_metadata('downloadPaths')
621+
if dests is None:
622+
# print(f"Skipping Image with Record Id: {rec_id}")
623+
continue
624+
619625
for d in dests:
620626
loc_dest = d['local_destination']
621627
src_url = d['url']
@@ -928,7 +934,7 @@ def cleanup_folders(self):
928934
self.download_path, '*.*'))
929935

930936
for f in downloads_files:
931-
file_date = datetime.datetime.fromtimestamp(os.path.getmtime(f))
937+
file_date = datetime.fromtimestamp(os.path.getmtime(f))
932938

933939
if file_date < downloads_start:
934940
# # print("The file %s will be deleted." % r)
@@ -1983,7 +1989,7 @@ def _finish_process(self, orders=None, in_imgs=None):
19831989

19841990
self.export_results()
19851991

1986-
end_time = datetime.datetime.now()
1992+
end_time = datetime.now()
19871993
end_str = end_time.strftime("%Y-%m-%d %H:%M:%S")
19881994

19891995
self.logger.info(f"End time: {end_str}")
@@ -1996,7 +2002,7 @@ def _set_result_fn(self):
19962002
:rtype: str
19972003
"""
19982004

1999-
start_time = datetime.datetime.now()
2005+
start_time = datetime.now()
20002006
start_str = start_time.strftime("%Y-%m-%d %H:%M:%S")
20012007
self.fn_str = start_time.strftime("%Y%m%d_%H%M%S")
20022008

@@ -2089,7 +2095,11 @@ def search_order_download(self, params):
20892095

20902096
# Print results info
20912097
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."
20932103
self.print_footer('Query Results', msg)
20942104

20952105
if no_order:
@@ -2494,9 +2504,25 @@ def download_available(self, params):
24942504

24952505
self.logger.info(f"Process start time: {start_str}")
24962506

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"\nGetting 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"\nGetting orders since {dtstart} "
2519+
f"(from entry RAPI.order_check_date set in the "
2520+
f"configuration file).\n")
2521+
24972522
################################################
24982523
# Get Existing Orders
24992524
################################################
2525+
orders = image.OrderList(self)
25002526
if self.order_items is not None and not self.order_items == '':
25012527
# Parse orders and order items
25022528
oi_split = self.order_items.split('|')
@@ -2512,7 +2538,6 @@ def download_available(self, params):
25122538
item_ids += ids
25132539

25142540
# orders = []
2515-
orders = image.OrderList(self)
25162541
for id in order_ids:
25172542
order = self.eodms_rapi.get_order(id)
25182543
if order is not None:
@@ -2529,15 +2554,17 @@ def download_available(self, params):
25292554

25302555
elif self.max_downloads is not None and not self.max_downloads == '':
25312556
ord_res = self.eodms_rapi.get_orders(max_orders=self.max_downloads,
2557+
dtstart=dtstart, dtend=dtend,
25322558
status='AVAILABLE_FOR_DOWNLOAD')
25332559
imgs = self.get_image_from_order(ord_res)
25342560
orders.ingest_results(ord_res, imgs)
25352561
else:
25362562
max_orders = 250
2537-
orders = None
2563+
ord_res = None
25382564
# 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:
25402566
ord_res = self.eodms_rapi.get_orders(max_orders=max_orders,
2567+
dtstart=dtstart, dtend=dtend,
25412568
status='AVAILABLE_FOR_DOWNLOAD')
25422569
imgs = self.get_image_from_order(ord_res)
25432570
orders.ingest_results(ord_res, imgs)
@@ -2551,7 +2578,7 @@ def download_available(self, params):
25512578
self.exit_cli(1)
25522579

25532580
msg = f"Number of order items with status " \
2554-
f"AVAILABLE_FOR_DOWNLOAD: {orders.count()}"
2581+
f"AVAILABLE_FOR_DOWNLOAD: {orders.count_items()}"
25552582
print(f"\n{msg}")
25562583
self.logger.info(msg)
25572584

0 commit comments

Comments
 (0)