Skip to content

Commit b0672af

Browse files
committed
adding id prefix
1 parent 561c2da commit b0672af

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

register_stac.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def fetch_s5_metadata(product_url, title, metadata_dir):
272272
request_with_progress(url, output_file)
273273

274274

275-
def regenerate_href_links(stacfile_path, metadata_dir, product_url):
275+
def regenerate_href_links(stacfile_path, metadata_dir, product_url, salt):
276276
"""
277277
Replaces href links in the final json containing the local path to contain the OData path and format.
278278
Cannot use stactools' create_item function parameters for this change, as the stac module is then actually reading
@@ -285,12 +285,18 @@ def regenerate_href_links(stacfile_path, metadata_dir, product_url):
285285
with (open(stacfile_path, 'r') as infile, open(new_file, 'w') as outfile):
286286
for line in infile:
287287
if metadata_dir in line:
288+
# replace file links
288289
split_line = line.split('"') # [' ', 'href', ': ', 'matadata_dir/resource/path', '\n']
289290
url_path_segments = split_line[-2].split(f"{metadata_dir}{'/'}")[1].split("/")
290291
correct_link = product_url + ''.join(
291292
f"/Nodes('{segment}')" for segment in url_path_segments) + "/$value"
292293
split_line[-2] = correct_link
293294
outfile.write('"'.join(split_line))
295+
elif '"id":' in line and salt:
296+
# prefix title, so unique UUID is generated if same product comes from different sources
297+
split_line = line.split('": "')
298+
salted_line = split_line[0] + '": "' + salt + split_line[1]
299+
outfile.write(salted_line)
294300
else:
295301
outfile.write(line)
296302
os.replace(new_file, stacfile_path)
@@ -398,6 +404,7 @@ def main():
398404
die_with_error("Flag --push was provided, but SUCC_PREFIX and ERR_PREFIX need to be set in the configuration "
399405
"file for logging!")
400406

407+
salt = config.get("SALT")
401408
if args.push and not stac_host:
402409
die_with_error('--push requires --stacHost argument or STAC_HOST configuration option to be set!')
403410

@@ -444,7 +451,7 @@ def main():
444451
print(f"Writing metadata to file: {stac_filepath}")
445452
item.save_object(dest_href=stac_filepath, include_self_link=False)
446453

447-
regenerate_href_links(stac_filepath, metadata_dir, product_url)
454+
regenerate_href_links(stac_filepath, metadata_dir, product_url, salt)
448455

449456
if args.push:
450457
upload_to_catalogue(stac_host, stac_filepath, overwrite=args.overwrite)

sentinel_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LOCAL_DIR: "/var/tmp/sentinel/"
66
SUCC_PREFIX: "/var/tmp/sentinel/register-stac-success-"
77
ERR_PREFIX: "/var/tmp/sentinel/register-stac-error-"
88
STAC_HOST: "https://stac.cesnet.cz"
9+
SALT: "dhr1" # if defined, will be used to prefix the ID

0 commit comments

Comments
 (0)