Skip to content

Commit

Permalink
Fix fromisoformat for python 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Apr 29, 2024
1 parent c84e4a6 commit 360c4bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 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 @@ -105,18 +105,18 @@ def run_every(interval):

def update_last_publication_date(last_publication_date, metadata):
"""Update the last publication data based on the metadata."""
publication_date = _fromisoformat(metadata)
publication_date = _fromisoformat(metadata["PublicationDate"])
if publication_date > last_publication_date:
last_publication_date = publication_date
return last_publication_date


def _fromisoformat(metadata):
def _fromisoformat(datestring):
try:
return datetime.datetime.fromisoformat(metadata["PublicationDate"])
return datetime.datetime.fromisoformat(datestring)
except ValueError:
# for python 3.10
return datetime.datetime.strptime(metadata["PublicationDate"], "%Y-%m-%dT%H:%M:%S.%f%z")
return datetime.datetime.strptime(datestring, "%Y-%m-%dT%H:%M:%S.%f%z")


def generate_download_links_since(filter_string, dataspace_auth, last_publication_date, storage_options):
Expand Down
8 changes: 4 additions & 4 deletions src/pytroll_watchers/dhus_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from geojson import Polygon
from upath import UPath

from pytroll_watchers.dataspace_watcher import run_every
from pytroll_watchers.dataspace_watcher import _fromisoformat, run_every
from pytroll_watchers.publisher import file_publisher_from_generator

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -109,10 +109,10 @@ def generate_download_links(server, filter_params):
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"] = dt.datetime.fromisoformat(results_dict["Ingestion Date"])
mda["ingestion_date"] = _fromisoformat(results_dict["Ingestion Date"])
mda["product_type"] = results_dict["Product type"]
mda["start_time"] = dt.datetime.fromisoformat(results_dict["Sensing start"])
mda["end_time"] = dt.datetime.fromisoformat(results_dict["Sensing stop"])
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["checksum"] = dict(algorithm=entry["Checksum"]["Algorithm"], hash=entry["Checksum"]["Value"])
Expand Down

0 comments on commit 360c4bb

Please sign in to comment.