Converted terrain2wiki script to Python 3
This commit is contained in:
parent
fccd419429
commit
0807990ae1
1 changed files with 6 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python
|
||||
#!/usr/bin/python3
|
||||
# encoding: utf-8
|
||||
|
||||
"""
|
||||
|
@ -6,15 +6,10 @@ 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"
|
||||
|
@ -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
|
||||
|
@ -97,12 +92,12 @@ dest='output_path', help="The location of the output file.")
|
|||
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue