Skip to content

Instantly share code, notes, and snippets.

@altendky
Created November 13, 2016 23:23
Show Gist options
  • Save altendky/92f4323bfd94e67cfbdc710a6393b318 to your computer and use it in GitHub Desktop.
Save altendky/92f4323bfd94e67cfbdc710a6393b318 to your computer and use it in GitHub Desktop.
diff --git a/wiki2html.py b/wiki2html.py
index 542ed9d..f31580b 100644
--- a/wiki2html.py
+++ b/wiki2html.py
@@ -17,13 +17,16 @@ import traceback
tree = ET.parse('your.xml', encoding='utf8')
root = tree.getroot()
-items = (['Category:', 'User talk:', 'Template:', 'User:', 'Shadowrun talk:', 'File:', 'Talk:',
- 'Shadowrun Wiki:', 'User blog:', 'User blog comment:'])
+items = ['Category', 'User talk', 'Template', 'User', 'Shadowrun talk', 'File', 'Talk',
+ 'Shadowrun Wiki', 'User blog', 'User blog comment']
for elem in root.iter():
- if ('export-0.6/}title' in elem.tag and elem.text is not None and items not in elem.text.split(':')[0]):
+ if elem.text is None:
+ continue
+
+ if ('export-0.6/}title' in elem.tag and elem.text.split(':')[0] not in items):
filestrip = re.sub(r'[\;*?!<>|/:"]', '', elem.text)
- fname = (os.path.join(filestrip.strip().replace(' ', '_')+'.html'))
+ fname = os.path.join(filestrip.strip().replace(' ', '_')+'.html')
title = re.sub('[/:"]', '', elem.text)
try:
hfile = open(fname, 'ab')
@@ -32,7 +35,7 @@ for elem in root.iter():
except Exception as e:
print(str(e))
- if 'export-0.6/}text' in elem.tag and elem.text is not None:
+ if 'export-0.6/}text' in elem.tag:
hfile.write('<link rel="stylesheet" href="style.css" type="text/css" media="screen" />')
hfile.write('<pre>')
hfile.write(elem.text.replace('[', '<b>').replace(']', '</b>').replace('\'', ''))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment