You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.5 KiB
Python

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
md_files = os.listdir(card_folder_path)
#print(md_files)
for md_file in md_files:
file_path = os.path.join(card_folder_path, md_file)
#print(file_path)
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)
number_pages = 2
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'''
<div class="page">
<div class="card">{card_1}</div>
<div class="card">{card_2}</div>
<div class="card">{card_3}</div>
<div class="card">{card_4}</div>
<div class="card">{card_5}</div>
<div class="card">{card_6}</div>
<div class="card">{card_7}</div>
<div class="card">{card_8}</div>
</div>
'''
pages.append(page_html)
print(page_html)
#print(pages)
pages_string = "\n".join(pages)
html_template = f'''
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<link href="https://fonts.cdnfonts.com/css/fjord" rel="stylesheet">
<link href="https://fonts.cdnfonts.com/css/notcouriersans" rel="stylesheet">
</head>
<body>
{pages_string}
</body>
</html>
'''
print(html_template)
with open('notebooks.html', 'w') as out:
out.write(html_template)