summaryrefslogtreecommitdiff
path: root/utils/update-item-db.py
diff options
context:
space:
mode:
authorLivio Recchia <recchialivio@libero.it>2020-02-10 23:06:34 +0100
committerLivio Recchia <recchialivio@libero.it>2020-02-10 23:06:34 +0100
commit9a13903a2f7d3a65fdf15a65fb59cccd622e2066 (patch)
tree9403b7dff39eb5e5d7fa0f79efb69b496add4c4b /utils/update-item-db.py
parent11cc316b74d5f3f283413a33e7693b314741aa4a (diff)
downloadmanachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.gz
manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.bz2
manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.xz
manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.zip
Initial commit
Diffstat (limited to 'utils/update-item-db.py')
-rw-r--r--utils/update-item-db.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/utils/update-item-db.py b/utils/update-item-db.py
new file mode 100644
index 0000000..27969de
--- /dev/null
+++ b/utils/update-item-db.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+
+"""
+Update text file containing item IDs and names.
+Author: Joseph Botosh <rumly111@gmail.com>
+Licence: GPLv2.
+"""
+
+import os
+import sys
+from xml.etree.ElementTree import ElementTree
+
+
+def ScanItemsXML(filename):
+ result = []
+ file1 = ElementTree(file=filename)
+ for item1 in filter(lambda it: it.get('name'), file1.getroot()):
+ file2 = ElementTree(file=item1.get('name'))
+ for item2 in filter(lambda it: it.get('name'), file2.getroot()):
+ file3 = ElementTree(file=item2.get('name'))
+ for item3 in file3.getroot():
+ name = item3.get('name')
+ id_ = item3.get('id')
+ if name is not None and id_ is not None and int(id_) > 0:
+ result.append((id_, name))
+ return result
+
+
+def PrintHelp():
+ print('Usage: {} <items.xml>'.format(sys.argv[0]))
+
+if __name__ == '__main__':
+ if len(sys.argv) == 1:
+ PrintHelp()
+ sys.exit(0)
+ filename = sys.argv[1]
+ if os.path.isfile(filename):
+ for id_, name in ScanItemsXML(filename):
+ print(id_, name)
+ else:
+ print('File not found:', filename, file=sys.stderr)
+ sys.exit(1)