Created
August 19, 2019 22:22
-
-
Save aalok-sathe/5f1a4f15bc17127966605deda64fb386 to your computer and use it in GitHub Desktop.
Takes in a CSV file with names/text, one on each line, and sequentially generates ASCII art for each line content, confirming the font for that before fixing the rendered output. Use the fontlist at the beginning of the script to add/remove fonts of your choosing from the `art` python package. Give a ridiculously large number for `howmany` if yo…
This file contains 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
#! /usr/bin/env python3 | |
#### | |
# A program to generate door decorations for incoming students based on their | |
# names using some nice ASCII (a.k.a. computer-generated) art. | |
# GPL 3+ | |
# (C) 2019 Aalok S. | |
from art import text2art | |
import csv | |
from pathlib import Path | |
import itertools | |
import re | |
import random | |
fonts = itertools.cycle([ | |
'6x10', | |
'alligator3', | |
'asc', | |
'banner3', | |
'bell', | |
#'block', | |
'charact2', | |
'colossal', | |
#'cybermedium', | |
'epic', | |
'georgia11', | |
#'graceful', | |
'jacky', | |
'poison', | |
'starwars', | |
]) | |
rosterfile = Path(input('enter path to your roster stored as a csvfile:\t')) | |
names = [] | |
with rosterfile.open('r') as csvfile: | |
reader = csv.reader(csvfile) | |
for row in reader: | |
names += [row[0]] | |
random.shuffle(names) | |
print() | |
input(''' | |
ascii arts for each name will now be generated. if you don\'t like the | |
output for a particular name, say \'n\', at the prompt and a new font | |
will be used until you find one you like. press any key to continue\n | |
''') | |
def grouper(iterable, n, fillvalue=None): | |
"Collect data into fixed-length chunks or blocks" | |
# grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx" | |
args = [iter(iterable)] * n | |
return itertools.zip_longest(*args, fillvalue=fillvalue) | |
howmany = int(input('howmany per page?\t')) | |
for i, name in enumerate(names): | |
with open('decs/decs%d.txt'%(i//howmany), 'a+') as out: | |
font = next(fonts) | |
rendered = text2art(text=name, font=font) | |
while input(font + '\n' + rendered + '\n(y/n)?\t') in ['n', 'N']: | |
font = next(fonts) | |
rendered = text2art(text=name, font=font) | |
print(rendered + '\n', file=out) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment