import os
from collections import namedtuple
Slide_show_name = "Materials"
Week_number = 0
number_of_slides = 8 # Only used without templates
title = Slide_show_name.replace(" ","%20")
base_audio_path = ("https://github.com/damontallen/Construction-materials/raw/master/Lecture_Audio"
"/Week_%d"
"/%s/%s-Slide_Title.mp3"%(Week_number,title,title))
# By using the lecture title as part of the file name it is far less likely that audio files
# will be overwritten by files for other lectures.
s_temp = namedtuple("SlideTemplate","topic content_stub subslide_count")
basic_slide_topics = [s_temp("Sustainability","In order to make ____ sustainability ",None),
s_temp("Toxicity and the Environment","____ is toxic to ",None),
s_temp("Recycling","____ can be recycled if ",None),
s_temp("Reuse","It is better if ____ can be reused in applications like ",None),
s_temp("Material Properties",None,None),
s_temp("Strength",None,None),
s_temp("Structural Failure Modes","____ will fail if it is subjected to ",None),
s_temp("Environment Induced Failure Modes","____ can be damaged by repeated exposure to ",
None),
s_temp("Chemical Weaknesses",("X is one of the compounds that you must "
"avoide having ____ exposed to. It "),None),
s_temp("Safe Operating Temperatures",("____ should only be used in the following "
"temperature ranges."),None),
s_temp("Material Tests","The main material tests that are relevant to ____ are ",None),
s_temp("Quality Levels","____ can be found in the following grades.",None),
s_temp("Residential Applications","____ is used in residential arena as ",None),
s_temp("Commercial Applications","____ is used in commercial buildings as ",None),
s_temp("Industrial Applications","____ is used in the industrial setting as ",None),
s_temp("Cost Examples","____ is generally sold as (by the)",None),
s_temp("Material Sources","Depending on the quanity you can purchase ____ from ",None),
s_temp("Examples of Installation Tools",("Though you are unlikely to be installing "
"any ____ personally, if you did, you are "
"likely to need "),None),
s_temp("Famous Failures","One of the more famous instances of a failure of ____",None),]
assembeled_slide_topics = [""]
sustainability_topics = [s_temp("Environmental Product Declarations (EPDs)",None,None),
s_temp("Lifecycle Cost",None,None),
s_temp("Carbon Footprint Index (CFI)",None,None),
s_temp("Volatile Organic Compound (VOC)",None,None),
s_temp("LEED",None,None),
s_temp("Cradle to Gate (CTG)",None,None),
s_temp("Sumary",None,None),]
materials_topics = [s_temp("Introduction",None,None),
s_temp("Material Properties",None,None),
s_temp("Young's Modulus",None,None),
s_temp("Plastic Behavior",None,None),
s_temp("Ultimate Strength",None,None),
s_temp("Energy Absorption - Toughness",None,None),
s_temp("Fracture Point",None,None),
s_temp("Repture",None,None),
s_temp("Shear Failure",None,None),
s_temp("Deformations",None,None),
s_temp("Buckling",None,None),
s_temp("Connections",None,None),
s_temp("Summary",None,None),]
# slide_template = None
#slide_template = basic_slide_topics
#slide_template = assembeled_slide_topics
#slide_template = sustainability_topics
slide_template = materials_topics
if slide_template == None:
content = [r'"* [%s](#)\n"'%Slide_show_name]
content += [r'" * [Slide %d Title](#/%d)\n"'%(i-1, i) for i in range(2,number_of_slides+3)]
content += [r'" * [References](#/%d)\n"'%(number_of_slides+3)]
else:
content = [r'"* [%s](#)\n"'%Slide_show_name]
content += [r'" * [%s](#/%d)\n"'%(s.topic, i+3) for i, s in enumerate(slide_template)]
content += [r'" * [References](#/%d)\n"'%(len(slide_template)+3)]
table_of_content = ",\n ".join(content)
table_default = r'''"* [Lecture Title](#)\n",
" * [Slide Title](#/2)\n",
" * [Sub-Slide Title](#/2/1)\n",
" * [References](#/4)\n"'''
# print(table_of_content)
path = "./Slideshow_source/"
header = path+"Blank Lecture Header.txt"
table = path+"Table of Contents.txt"
slide = path+"Blank Lecture Main Slides.txt"
subslide = path+"Blank Lecture Sub Slides.txt"
footer = path+"Blank Lecture Footer.txt"
original_title = "Lecture Title"
with open(header, 'r') as f:
txt = f.read()
txt = txt.replace(original_title, Slide_show_name)
with open(table, 'r') as f:
empty_table = f.read()
txt+=empty_table.replace(table_default,table_of_content)
with open(slide, 'r') as f:
slide_txt = f.read()
# Fix audio path
# slide_txt = slide_txt.replace("Week_1","Week_%d"%Week_number)
# slide_txt = slide_txt.replace("Lecture_Title",Slide_show_name)
slide_txt = slide_txt.replace('mp3 Path',base_audio_path)
with open(subslide, 'r') as f:
subslide_txt = f.read()
subslide_txt = subslide_txt.replace('mp3 Path',base_audio_path)
if slide_template is None:
for i in range(number_of_slides):
slide = slide_txt.replace("Slide Title", "Slide %d Title"%(i+1))
txt += slide
else:
for s in slide_template:
slide = slide_txt.replace("Slide Title", s.topic)
if s.content_stub:
slide = slide.replace("Slide Content", s.content_stub)
slide = slide.replace('Slide_Title',s.topic.replace(' ','%20'))
slide = slide.replace('Edit Slide Audio','')
txt += slide
if s.subslide_count:
for i in range(s.subslide_count):
txt += subslide_txt
with open(footer, 'r') as f:
txt += f.read()
d = "./Lecture_Audio/Week_%d/%s"%(Week_number,Slide_show_name)
if not os.path.exists(d):
os.makedirs(d)
if slide_template is not None:
for s in slide_template:
file_path = d+'/%s-'%Slide_show_name+s.topic+'.mp3'
with open(file_path,'a') as f:
pass
notebook = Slide_show_name+".ipynb"
if os.path.exists(notebook):
choice = input("Notebook already exists! Do you wish to overwrite? y[N] ")
if choice == "":
choice = 'n'
else:
choice = 'y'
choice = choice.strip().lower()
if 'y' in choice:
with open(notebook,'w')as f:
f.write(txt)
print("Notebook created!")
Notebook created!