Skip to content

Commit

Permalink
OARec wcmp2 fixes (#235)
Browse files Browse the repository at this point in the history
* OARec: fix date-time and phone formatting

* fix ref
  • Loading branch information
tomkralidis authored Oct 7, 2023
1 parent f8bfde3 commit ec348bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions pygeometa/schemas/ogcapi_records/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import os
from typing import Union

from pygeometa.core import get_charstring, normalize_datestring
from pygeometa.core import get_charstring
from pygeometa.helpers import json_serial
from pygeometa.schemas.base import BaseOutputSchema

Expand Down Expand Up @@ -157,12 +157,17 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
record['properties']['created'] = str(mcf['identification']['dates']['creation']) # noqa
if 'revision' in mcf['identification']['dates']:
record['properties']['updated'] = str(mcf['identification']['dates']['revision']) # noqa
if 'publication' in mcf['identification']['dates']:
record['properties']['updated'] = normalize_datestring(mcf['identification']['dates']['publication']) # noqa

if record['properties'].get('created') is None:
record['properties']['created'] = datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ') # noqa

for date_type in ['created', 'updated']:
ds = record['properties'].get(date_type)
if ds is not None and len(ds) == 10:
LOGGER.debug('Date type found; expanding to date-time')
dt = datetime.strptime(ds, '%Y-%m-%d').strftime('%Y-%m-%dT%H:%M:%SZ') # noqa
record['properties'][date_type] = dt

rights = get_charstring(mcf['identification'].get('rights'),
self.lang1, self.lang2)

Expand Down Expand Up @@ -308,7 +313,12 @@ def generate_party(self, contact: dict,
rp['addresses'][0]['country'] = country[0]

if contact.get('phone') is not None:
rp['phones'] = [{'value': contact.get('phone')}]
LOGGER.debug('Formatting phone number')
phone = contact['phone']
phone = phone.replace('-', '').replace('(', '').replace(')', '')
phone = phone.replace('+0', '+').replace(' ', '')

rp['phones'] = [{'value': phone}]
if contact.get('email') is not None:
rp['emails'] = [{'value': contact.get('email')}]

Expand Down
2 changes: 1 addition & 1 deletion pygeometa/schemas/wmo_wcmp2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
except KeyError:
LOGGER.warning('Missing wmo:dataPolicy')

if 'dates' not in record['properties']:
if 'created' not in record['properties']:
record['properties']['created'] = datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ') # noqa

if stringify:
Expand Down

0 comments on commit ec348bc

Please sign in to comment.