blob: a77cb810fde5a3d2be9cc027d17a9418f3e39678 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/usr/bin/python
"""
Update text file containing monster 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: {} <monsters.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)
|