diff options
Diffstat (limited to 'scripts/tellico2lesana')
-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: |