Skip to content

Instantly share code, notes, and snippets.

@jtmcx
Last active October 23, 2019 18:07
Show Gist options
  • Save jtmcx/c0d3714fa89ac8560abd0ac04ba57d24 to your computer and use it in GitHub Desktop.
Save jtmcx/c0d3714fa89ac8560abd0ac04ba57d24 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
import argparse
def parse_args():
parser = argparse.ArgumentParser(description="Process some stuff.")
parser.add_argument("-w", "--width", type=int, help="width of map", required=True)
parser.add_argument(
"-ht", "--height", type=int, help="height of map", required=True
)
parser.add_argument("input", type=str, help="input blk file")
return parser.parse_args()
def main():
args = parse_args()
with open(args.input, "rb") as f:
data = f.read()
data = [int(x) for x in data]
if len(data) != args.width * args.height:
raise ValueError("bad dimensions")
for i in range(int(len(data) / args.height)):
start_index = i * args.height
row = data[start_index : start_index + args.width]
print(",".join([str(x) for x in row]))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment