Skip to content

Instantly share code, notes, and snippets.

@memilanuk
Created February 19, 2018 21:09
Show Gist options
  • Save memilanuk/c6e0bb9f98076a172d4f39d044ed6ecf to your computer and use it in GitHub Desktop.
Save memilanuk/c6e0bb9f98076a172d4f39d044ed6ecf to your computer and use it in GitHub Desktop.
# bswn.py -- Munge results from BSWN events to a usable format
import csv
with open('data.txt','r') as input_file:
lines = input_file.read().split('\n')
# Remove the first 8 lines of tile, header, etc.
lines = lines[8:]
for line in lines:
# Strip out the class separator lines
if line.startswith(' '):
lines.remove(line)
with open('output.csv', 'w') as output_file:
fieldnames = ['name', 'class']
writer = csv.DictWriter(output_file, fieldnames=fieldnames)
for i in range(len(lines)):
writer.writerow({'name': lines[i][:21],
'class': lines[i][22:32]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment