aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-03-25 18:37:36 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-03-25 18:37:36 +0100
commit2a824fab4e4b48184583b639f6753ab051f4dd55 (patch)
tree0bc9c436a6047ce3cd1bc371988c46ccd8bbd0b1 /scripts
parent4d0fbfdd140e4c226d51a9f941d26cb44001c78e (diff)
Start writing a tellico importer
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/tellico2lesana66
1 files changed, 66 insertions, 0 deletions
diff --git a/scripts/tellico2lesana b/scripts/tellico2lesana
new file mode 100755
index 0000000..8de8bf9
--- /dev/null
+++ b/scripts/tellico2lesana
@@ -0,0 +1,66 @@
+#!/usr/bin/env python3
+
+from xml.etree import ElementTree
+import zipfile
+
+import guacamole
+
+
+XML_NS = '{http://periapsis.org/tellico/}'
+
+# https://docs.kde.org/trunk5/en/extragear-office/tellico/field-type-values.html
+F_TYPE_MAP = {
+ '1': 'string',
+ '2': 'text',
+ '3': 'string',
+ '4': 'bool',
+ '6': 'integer',
+ '7': 'url',
+ '8': 'list', # single column table
+ '10': 'file',
+ '12': 'timestamp', # date
+ '14': 'integer', # rating
+
+ }
+
+
+class T2L(guacamole.Command):
+ """
+ Manage collections
+ """
+
+ def register_arguments(self, parser):
+ parser.add_argument(
+ 'file',
+ help='Tellico file to convert to lesana.'
+ )
+
+ def invoked(self, ctx):
+ with zipfile.ZipFile(ctx.args.file, 'r') as zp:
+ tree = ElementTree.parse(zp.open('tellico.xml'))
+ # open collection
+ xml_collection = tree.getroot().find(XML_NS+'collection')
+
+ # get collection settings
+ title = xml_collection.attrib['title']
+ xml_fields = xml_collection.find(XML_NS+'fields')
+ fields = []
+ for xf in xml_fields:
+ print(xf.attrib)
+ f_type = F_TYPE_MAP.get(xf.attrib['format'])
+ # TODO: support fields with the multiple values flag
+ # (they should probably become lists)
+ fields.append({
+ 'name': xf.attrib['title'],
+ 'type': f_type,
+ })
+ # TODO: create a collection with the following settings:
+ import ruamel.yaml
+ print(ruamel.yaml.dump({'title': title, 'fields': fields}))
+
+ # import data
+
+
+
+if __name__ == '__main__':
+ T2L().main()