import os import markdown from random import choice # Get the directory path of the script script_dir = os.path.dirname(os.path.abspath(__file__)) materials = ['1_situation', '2_binding', '3_paperformat', '4_add_ons'] cards = { '1_situation' : { 'content' : [], 'make-a-notebook-that' : [] }, '2_binding' : { 'content' : [], 'make-a-notebook-that' : [] }, '3_paperformat' : { 'content' : [], 'make-a-notebook-that' : [] }, '4_add_ons' : { 'content' : [], 'make-a-notebook-that' : [] } } for folder in materials: material_folder_path = os.path.join(script_dir, folder) card_folders = os.listdir(material_folder_path) #print(material_folder_path) for card_folder in card_folders: card_folder_path = os.path.join(material_folder_path, card_folder) #print(card_folder_path) #these are content and make a notebook that folders paths my_files = os.listdir(card_folder_path) #print(my_files) for my_file in my_files: file_path = os.path.join(card_folder_path, my_file) relative_file_path = os.path.relpath(file_path, os.path.dirname(__file__)) #image_path = #print(file_path) #print(relative_file_path) if my_file.endswith(('.md', '.markdown')): with open(file_path, 'r') as file: md = file.read() card = markdown.markdown(md) #print(card) # the print of all the md files cards[folder][card_folder].append(card) elif my_file.endswith(('.jpg', '.jpeg', '.png')): image_html = f'{my_file}' cards[folder][card_folder].append(image_html) #print(card_folder) #print(file_path) number_pages = 32 pages = [] for page in range(number_pages): card_1= choice(cards["1_situation"]["content"]) cards["1_situation"]["content"].remove(card_1) card_2= choice(cards["1_situation"]["make-a-notebook-that"]) cards["1_situation"]["make-a-notebook-that"].remove(card_2) card_3= choice(cards["2_binding"]["content"]) cards["2_binding"]["content"].remove(card_3) card_4= choice(cards["2_binding"]["make-a-notebook-that"]) cards["2_binding"]["make-a-notebook-that"].remove(card_4) card_5= choice(cards["3_paperformat"]["content"]) cards["3_paperformat"]["content"].remove(card_5) card_6= choice(cards["3_paperformat"]["make-a-notebook-that"]) cards["3_paperformat"]["make-a-notebook-that"].remove(card_6) card_7= choice(cards["4_add_ons"]["content"]) cards["4_add_ons"]["content"].remove(card_7) card_8= choice(cards["4_add_ons"]["make-a-notebook-that"]) cards["4_add_ons"]["make-a-notebook-that"].remove(card_8) page_html = f'''
{card_1}
{card_2}
{card_3}
{card_4}
{card_5}
{card_6}
{card_7}
{card_8}
''' pages.append(page_html) #print(page_html) #print(pages) pages_string = "\n".join(pages) html_template = f''' Document {pages_string} ''' #print(html_template) with open('notebooks.html', 'w') as out: out.write(html_template)