import os from glob import glob from pprint import pprint from random import choice import pypandoc import base64 # -------------------------------------------------- # Parameters # number of items on one page nr_of_items = 10 # number of different pages it will generate for each partyline nr_of_versions = 10 # you can download the materials with download-materials.sh materials_folder = "materials" # this is the folder where the bricolages will be saved to output_folder = "generated-bricolages" # for uploading the pages with images somehwere encode_imgs_as_base64 = True # -------------------------------------------------- # First make an index of all the files index = {} dir = f"./{ materials_folder }/*" folders = glob(dir, recursive=True) for folder in folders: name = folder.replace("./materials/", "") dir = folder + "/**" materials = glob(dir, recursive=True) index[name] = materials # pprint(index) # --------------------------------------------------- # Functions def parsePad(pad): """Parses pad into a list of

's""" html = open(pad, "r").read() paragraphs = html.split("
") paragraphs = [p for p in paragraphs if p] paragraphs = [p for p in paragraphs if not "body>" in p] paragraphs = [p for p in paragraphs if not "html>" in p] return paragraphs def parseAnnouncement(page): """Parses an announcement page from the website into a list of

's""" html = open(page, "r").read() paragraphs = html.split("\n") paragraphs = [p for p in paragraphs if p] paragraphs = [p for p in paragraphs if "

" in p] paragraphs = [p for p in paragraphs if not "body>" in p] paragraphs = [p for p in paragraphs if not "html>" in p] paragraphs = [p.replace("\t", "") for p in paragraphs] return paragraphs def parseAllItems(partyline): """Makes a list of all items of one partyline""" all_items = [] for item in index[partyline]: el = "" for ext in ["jpg","png","jpeg"]: if item.endswith(ext): if encode_imgs_as_base64 == True: img = open(item, "rb").read() img_in_base64 = base64.b64encode(img) el = f"" else: el = f"" all_items.append(el) if "pad.html" in item: paragraphs = parsePad(item) for paragraph in paragraphs: # do not wrap