Skip to content

Commit

Permalink
Privatize some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Apr 29, 2024
1 parent 002e778 commit 02d355e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/pytroll_watchers/dataspace_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def file_generator(filter_string,
for next_check in run_every(polling_interval):
generator = generate_download_links_since(filter_string, dataspace_auth, last_pub_date, storage_options)
for s3path, metadata in generator:
last_pub_date = update_last_publication_date(last_pub_date, metadata)
last_pub_date = _update_last_publication_date(last_pub_date, metadata)
yield s3path, metadata
logger.info("Finished polling.")
if next_check > datetime.datetime.now(datetime.timezone.utc):
Expand All @@ -103,7 +103,7 @@ def run_every(interval):
break


def update_last_publication_date(last_publication_date, metadata):
def _update_last_publication_date(last_publication_date, metadata):
"""Update the last publication data based on the metadata."""
publication_date = _fromisoformat(metadata.pop("PublicationDate"))
if publication_date > last_publication_date:
Expand Down Expand Up @@ -150,7 +150,7 @@ def generate_download_links(filter_string, dataspace_auth, storage_options):
for metadata in metadatas:
s3path = UPath("s3://" + metadata["S3Path"], **storage_options)
mda = dict()
attributes = construct_attributes_dict(metadata)
attributes = _construct_attributes_dict(metadata)
mda["platform_name"] = attributes["platformShortName"].capitalize() + attributes["platformSerialIdentifier"]
mda["sensor"] = attributes["instrumentShortName"].lower()
mda["PublicationDate"] = metadata["PublicationDate"]
Expand All @@ -169,7 +169,7 @@ def generate_download_links(filter_string, dataspace_auth, storage_options):
yield s3path, mda


def construct_attributes_dict(entry):
def _construct_attributes_dict(entry):
"""Construct a dict from then "results" item in entry."""
results = entry["Attributes"]
attributes = {result["Name"]: result["Value"] for result in results}
Expand Down
28 changes: 14 additions & 14 deletions src/pytroll_watchers/dhus_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ def file_generator(server, filter_params, polling_interval, start_from=None):
for next_check in run_every(polling_interval):
generator = generate_download_links_since(server, filter_params, last_pub_date)
for path, metadata in generator:
last_pub_date = update_last_publication_date(last_pub_date, metadata)
last_pub_date = _update_last_publication_date(last_pub_date, metadata)
yield path, metadata
logger.info("Finished polling.")
if next_check > dt.datetime.now(dt.timezone.utc):
logger.info(f"Next iteration at {next_check}")

Check warning on line 71 in src/pytroll_watchers/dhus_watcher.py

View check run for this annotation

Codecov / codecov/patch

src/pytroll_watchers/dhus_watcher.py#L71

Added line #L71 was not covered by tests


def update_last_publication_date(last_publication_date, metadata):
def _update_last_publication_date(last_publication_date, metadata):
"""Update the last publication data based on the metadata."""
publication_date = metadata.pop("ingestion_date")
if publication_date > last_publication_date:
Expand Down Expand Up @@ -105,28 +105,28 @@ def generate_download_links(server, filter_params):
for entry in entries["d"]["results"]:
mda = dict()
path = UPath(entry["__metadata"]["media_src"])
mda["boundary"] = extract_boundary(entry)
results_dict = construct_results_dict(entry)
mda["platform_name"] = results_dict["Satellite name"].capitalize() + results_dict["Satellite number"]
mda["sensor"] = results_dict["Instrument"]
mda["ingestion_date"] = _fromisoformat(results_dict["Ingestion Date"])
mda["product_type"] = results_dict["Product type"]
mda["start_time"] = _fromisoformat(results_dict["Sensing start"])
mda["end_time"] = _fromisoformat(results_dict["Sensing stop"])
mda["orbit_number"] = int(results_dict["Orbit number (start)"])
mda["boundary"] = _extract_boundary_as_geojson(entry)
attributes = _construct_attributes_dict(entry)
mda["platform_name"] = attributes["Satellite name"].capitalize() + attributes["Satellite number"]
mda["sensor"] = attributes["Instrument"]
mda["ingestion_date"] = _fromisoformat(attributes["Ingestion Date"])
mda["product_type"] = attributes["Product type"]
mda["start_time"] = _fromisoformat(attributes["Sensing start"])
mda["end_time"] = _fromisoformat(attributes["Sensing stop"])
mda["orbit_number"] = int(attributes["Orbit number (start)"])

mda["checksum"] = dict(algorithm=entry["Checksum"]["Algorithm"], hash=entry["Checksum"]["Value"])
mda["size"] = int(entry["ContentLength"])
yield path, mda

def construct_results_dict(entry):
def _construct_attributes_dict(entry):
"""Construct a dict from then "results" item in entry."""
results = entry["Attributes"]["results"]
results_dict = {result["Id"]: result["Value"] for result in results}
results_dict = {result["Name"]: result["Value"] for result in results}
return results_dict


def extract_boundary(entry):
def _extract_boundary_as_geojson(entry):
"""Extract the boundary from the entry metadata."""
gml, nsmap = read_gml(entry["ContentGeometry"])
boundary_text = gml.find("gml:outerBoundaryIs/gml:LinearRing/gml:coordinates", namespaces=nsmap).text
Expand Down

0 comments on commit 02d355e

Please sign in to comment.