Skip to content

Commit

Permalink
Converted terrain2wiki script to Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Elvish-Hunter committed Jun 22, 2016
1 parent fccd419 commit 0807990
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions data/tools/terrain2wiki.py
@@ -1,20 +1,15 @@
#!/usr/bin/python
#!/usr/bin/python3
# encoding: utf-8

"""
A script to create the "Terrain Table" on the TerrainCodeTableWML wiki page.
Add the output to the wiki whenever a new terrain is added to mainline.
"""

from __future__ import with_statement # For python < 2.6
import os
import sys
import re
try:
import argparse
except ImportError:
print('Please install argparse by running "easy_install argparse"')
sys.exit(1)
import argparse

# Where to get terrain images
terrain_url = "https://raw.github.com/wesnoth/wesnoth/master/data/core/images/terrain/%s.png"
Expand Down Expand Up @@ -64,7 +59,7 @@ def parse_terrain(data):
for text in removeus:
i = [a.replace(text, "") for a in i]
# Create a dictionary of key and values
content = dict([v.strip().split("=") for v in i])
content = {k: v for (k, v) in [p.strip().split("=", 1) for p in i]}
# Hidden things shouldn't be displayed
if 'hidden' in content:
continue
Expand Down Expand Up @@ -97,12 +92,12 @@ def parse_terrain(data):
output_path = args.output_path

if not os.path.exists(path) or not path.endswith('.cfg'):
print("Invalid path: '%s' does not exist or not a .cfg file.") % path
print("Invalid path: '%s' does not exist or not a .cfg file." % path)
sys.exit(1)

with open(path, "r") as input_file:
with open(path, "r", encoding="utf8") as input_file:
data = input_file.read()
data = parse_terrain(data)

with open(output_path, "w") as output:
with open(output_path, "w", encoding="utf8") as output:
output.write(data)

0 comments on commit 0807990

Please sign in to comment.