from collections import defaultdict
import random
import yaml
class GrawlixCodex():
def __init__(self, width=100, height=10, wordcount=50000):
self.width = width
self.height = height
self.smallest = 1
self.longest = 8
self.wordcount = wordcount
def config(self, cffile):
with open(cffile) as cf:
try:
self.cf = yaml.load(cf, Loader=yaml.Loader)
except yaml.YAMLError as exc:
print("%s parse error: %s" % ( self.args.config, exc ))
if hasattr(exc, 'problem_mark'):
mark = exc.problem_mark
print("Error position: (%s:%s)" % (mark.line + 1, mark.column + 1))
def load_emojos(self):
self.emojos = []
self.groups = defaultdict(set)
with open(self.cf["emojos"], "r") as efh:
for line in efh:
parts = line.split()
glyph = parts[0][1:-1]
self.emojos.append(glyph)
for tag in parts[1:]:
self.groups[tag].add(glyph)
self.tags = [ t for t in self.groups.keys() if not t == "blank" ]
self.blank = list(self.groups["blank"])[0]
def text(self):
for w in range(self.wordcount):
l = random.randint(self.smallest, self.longest)
for g in range(l):
yield random.choice(list(self.groups["glyph"]))
yield(self.blank)
def write(self):
row = []
for g in self.text():
row.append(g)
if len(row) == self.width:
glyphs = [ f'
' for g in row ]
print(''.join(glyphs))
print('
')
row = []
gc = GrawlixCodex()
gc.config("./config.yml")
gc.load_emojos()
gc.write()