Created
November 15, 2017 03:03
-
-
Save emanuelfeld/8faef5c380b06d87b6876603a3ce628c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import errno | |
import os | |
import sys | |
if __name__ == '__main__': | |
try: | |
with open(sys.argv[1], 'r') as infile: | |
text = infile.readlines() | |
except IndexError: | |
print('Usage: python arena_ascii.py txt_file_path') | |
sys.exit() | |
lines_per_block = 84 | |
row = [[],[],[]] | |
folder = 'ascii-' + sys.argv[1].split('.')[0] | |
try: | |
os.makedirs(folder) | |
except OSError as exception: | |
if exception.errno != errno.EEXIST: | |
raise | |
for nline in range(len(text)): | |
if (nline + 1) % lines_per_block == 0: | |
nrow = int((nline + 1) / lines_per_block - 1) | |
for ncol in range(3): | |
with open('{}/{}-{}.txt'.format(folder, nrow, ncol), 'w') as outfile: | |
outfile.write('\n'.join(row[ncol])) | |
row = [[],[],[]] | |
line = text[nline].strip() | |
row[0].append(line[:160]) | |
row[1].append(line[160:320]) | |
row[2].append(line[320:480]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment