4343#
4444# =================================================================
4545
46+ from datetime import datetime
4647import json
4748import logging
4849import os
@@ -140,9 +141,12 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
140141 else :
141142 end = str (end )
142143
143- record ['time' ] = {
144- 'interval' : [begin , end ]
145- }
144+ if [begin , end ] == [None , None ]:
145+ record ['time' ] = None
146+ else :
147+ record ['time' ] = {
148+ 'interval' : [begin , end ]
149+ }
146150
147151 if 'resolution' in mcf ['identification' ]['extents' ]['temporal' ][0 ]: # noqa
148152 record ['time' ]['resolution' ] = mcf ['identification' ]['extents' ]['temporal' ][0 ]['resolution' ] # noqa
@@ -153,10 +157,12 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
153157 record ['properties' ]['created' ] = str (mcf ['identification' ]['dates' ]['creation' ]) # noqa
154158 if 'revision' in mcf ['identification' ]['dates' ]:
155159 record ['properties' ]['updated' ] = str (mcf ['identification' ]['dates' ]['revision' ]) # noqa
156-
157160 if 'publication' in mcf ['identification' ]['dates' ]:
158161 record ['properties' ]['updated' ] = normalize_datestring (mcf ['identification' ]['dates' ]['publication' ]) # noqa
159162
163+ if record ['properties' ].get ('created' ) is None :
164+ record ['properties' ]['created' ] = datetime .now ().strftime ('%Y-%m-%dT%H:%M:%SZ' ) # noqa
165+
160166 rights = get_charstring (mcf ['identification' ].get ('rights' ),
161167 self .lang1 , self .lang2 )
162168
@@ -260,31 +266,40 @@ def generate_party(self, contact: dict,
260266 country = get_charstring (contact .get ('country' ),
261267 self .lang1 , self .lang2 )
262268
263- rp = {}
269+ rp = {
270+ 'addresses' : [{}],
271+ 'roles' : []
272+ }
264273
265274 if organization_name [0 ] == contact .get ('organization' ):
266275 LOGGER .debug ('Contact name is organization' )
267276 rp ['name' ] = organization_name [0 ]
268277
269- rp .update ({
270- 'positionName' : position_name [0 ],
271- 'phones' : [{
272- 'value' : contact .get ('phone' )
273- }],
274- 'emails' : [{
275- 'value' : contact .get ('email' )
276- }],
277- 'addresses' : [{
278- 'deliveryPoint' : [address [0 ]],
279- 'city' : city [0 ],
280- 'administrativeArea' : administrative_area [0 ],
281- 'postalCode' : postalcode [0 ],
282- 'country' : country [0 ]
283- }],
284- 'hoursOfService' : hours_of_service [0 ],
285- 'contactInstructions' : contact_instructions [0 ],
286- 'roles' : []
287- })
278+ if position_name [0 ] is not None :
279+ rp ['positionName' ] = position_name [0 ]
280+ if hours_of_service [0 ] is not None :
281+ rp ['positionName' ] = hours_of_service [0 ]
282+ if contact_instructions [0 ] is not None :
283+ rp ['contactInstructions' ] = contact_instructions [0 ]
284+
285+ if address [0 ] is not None :
286+ rp ['addresses' ][0 ]['deliveryPoint' ] = [address [0 ]]
287+ if city [0 ] is not None :
288+ rp ['addresses' ][0 ]['city' ] = city [0 ]
289+ if administrative_area [0 ] is not None :
290+ rp ['addresses' ][0 ]['administrativeArea' ] = administrative_area [0 ]
291+ if postalcode [0 ] is not None :
292+ rp ['addresses' ][0 ]['postalCode' ] = postalcode [0 ]
293+ if country [0 ] is not None :
294+ rp ['addresses' ][0 ]['country' ] = country [0 ]
295+
296+ if contact .get ('phone' ) is not None :
297+ rp ['phones' ] = [{'value' : contact .get ('phone' )}]
298+ if contact .get ('email' ) is not None :
299+ rp ['emails' ] = [{'value' : contact .get ('email' )}]
300+
301+ if rp ['addresses' ][0 ] == {}:
302+ rp .pop ('addresses' )
288303
289304 for r in set (roles ):
290305 rp ['roles' ].append (r )
@@ -350,13 +365,15 @@ def generate_link(self, distribution: dict) -> dict:
350365
351366 name = get_charstring (distribution .get ('name' ), self .lang1 , self .lang2 )
352367
353- reltype = distribution .get ('rel' ) or distribution .get ('function' )
354-
355368 link = {
356- 'rel' : reltype ,
357369 'href' : distribution ['url' ],
358370 'type' : distribution ['type' ]
359371 }
372+
373+ reltype = distribution .get ('rel' ) or distribution .get ('function' )
374+ if reltype is not None :
375+ link ['rel' ] = reltype
376+
360377 if title != [None , None ]:
361378 link ['title' ] = title [0 ]
362379 elif name != [None , None ]:
0 commit comments