diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2017-08-05 18:41:38 +0200 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2017-08-05 18:41:38 +0200 |
commit | 043e99bf5416e0899c02490fa600be4cfd049da1 (patch) | |
tree | 031370d603644cf91f281e3c3940118a4d1dff1c | |
parent | ba79c95627a0a650721d73cddaf43be6a89bc6c6 (diff) |
Correctly load date fields
-rwxr-xr-x | scripts/tellico2lesana | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/scripts/tellico2lesana b/scripts/tellico2lesana index 7b4df16..0b0ec64 100755 --- a/scripts/tellico2lesana +++ b/scripts/tellico2lesana @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import datetime from xml.etree import ElementTree import zipfile @@ -44,7 +45,23 @@ class T2L(guacamole.Command): ) def read_field_data(self, xfield): - if xfield.iter().__next__(): + if xfield.tag in self.date_fields: + for child in xfield: + if 'year' in child.tag: + year = child.text + elif 'month' in child.tag: + month = child.text + elif 'day' in child.tag: + day = child.text + try: + data = datetime.date( + int(year), + int(month), + int(day) + ) + except ValueError: + data = None + elif xfield.iter().__next__(): data = [] for child in xfield: data.append(self.read_field_data(child)) @@ -62,9 +79,14 @@ class T2L(guacamole.Command): # get collection settings title = xml_collection.attrib['title'] xml_fields = xml_collection.find('tellico:fields', NS) + self.date_fields = [] fields = [] for xf in xml_fields: - f_type = F_TYPE_MAP.get(xf.attrib['format']) + if xf.attrib['type'] == '12': + self.date_fields.append( + '{' + NS['tellico'] + '}' + xf.attrib['name'] + ) + f_type = F_TYPE_MAP.get(xf.attrib['type']) # TODO: support fields with the multiple values flag # (they should probably become lists) try: |