<gh_stars>0
import os

def get_subdirectories_in_directory(dir):
    for root, dirs, files in os.walk(dir, topdown=True):
        return dirs

if __name__ == "__main__":

    print("generating new index.html file...")
    index_template = open("templates/index_template", 'r')
    index_template_string = index_template.read()
    index_template.close()

    print("filling sidebar...")
    sidebar_dropdown_template = open("templates/sidebar_dropdown_template", 'r').read()
    sidebar_entry_template = open("templates/sidebar_entry_template", 'r').read()
    sidebar_string = open("templates/sidebar_template", 'r').read()

    sidebar_dropdowns = []

    all_presentations = []

    i = 0
    for subdir in get_subdirectories_in_directory("./media"):
        sub_title = open("./media/" + subdir + "/SubDirTitle.txt").read()
        string = sidebar_dropdown_template.replace("||SUBMENU_NAME||", subdir).replace("||SUBMENU_TITLE||", sub_title)

        entries = []
        for entry in get_subdirectories_in_directory("./media/" + subdir):
            entry_name = open("./media/" + subdir + '/' + entry + "/EntryName.txt").read()
            all_presentations.append("media/" + subdir + '/' + entry)
            entries.append(sidebar_entry_template.replace("||ENTRY_LINK||", "/media/" + subdir + '/' + entry + "/entry.html").replace("||ENTRY_TITLE||", entry_name))
        
        all_entries = ""
        for e in entries:
            all_entries += e
        sidebar_dropdowns.append(string.replace("||SUBMENU_ENTRIES||", all_entries))
    
    all_dropdowns = ""
    for dropdown in sidebar_dropdowns:
        all_dropdowns += dropdown

    sidebar_string = sidebar_string.replace("||SIDEBAR_DROPDOWNS||", all_dropdowns)

    index_template_string = index_template_string.replace("||SIDEBAR||", sidebar_string)

    print("writing to new index.html...")
    index_file = open("index.html", 'w')
    index_file.write(index_template_string)

    print("creating presentations...")
    revealjs_template = open("templates/revealjs_template", 'r').read()
    revealjs_video_template = open("templates/revealjs_video_section_template", 'r').read()
    for presentation in all_presentations:
        print(presentation)
        movie_files = []
        unprocessed_lines = open(presentation + "/partial_movie_file_list.txt").readlines()[1:]
        for l in unprocessed_lines:
            movie_files.append('/' + presentation + '/' + l.split('/')[-1].replace('\'', '').replace('\n', ''))
        
        video_sections = ""
        for v in movie_files:
            video_sections += revealjs_video_template.replace("||VIDEO_LINK||", v)
        
        open(presentation + '/entry.html', 'w').write(revealjs_template.replace("||SECTIONS||", video_sections))
        
        

import os

def get_subdirectories_in_directory(dir):
    for root, dirs, files in os.walk(dir, topdown=True):
        return dirs

if __name__ == "__main__":

    print("generating new index.html file...")
    index_template = open("templates/index_template", 'r')
    index_template_string = index_template.read()
    index_template.close()

    print("filling sidebar...")
    sidebar_dropdown_template = open("templates/sidebar_dropdown_template", 'r').read()
    sidebar_entry_template = open("templates/sidebar_entry_template", 'r').read()
    sidebar_string = open("templates/sidebar_template", 'r').read()

    sidebar_dropdowns = []

    all_presentations = []

    i = 0
    for subdir in get_subdirectories_in_directory("./media"):
        sub_title = open("./media/" + subdir + "/SubDirTitle.txt").read()
        string = sidebar_dropdown_template.replace("||SUBMENU_NAME||", subdir).replace("||SUBMENU_TITLE||", sub_title)

        entries = []
        for entry in get_subdirectories_in_directory("./media/" + subdir):
            entry_name = open("./media/" + subdir + '/' + entry + "/EntryName.txt").read()
            all_presentations.append("media/" + subdir + '/' + entry)
            entries.append(sidebar_entry_template.replace("||ENTRY_LINK||", "/media/" + subdir + '/' + entry + "/entry.html").replace("||ENTRY_TITLE||", entry_name))
        
        all_entries = ""
        for e in entries:
            all_entries += e
        sidebar_dropdowns.append(string.replace("||SUBMENU_ENTRIES||", all_entries))
    
    all_dropdowns = ""
    for dropdown in sidebar_dropdowns:
        all_dropdowns += dropdown

    sidebar_string = sidebar_string.replace("||SIDEBAR_DROPDOWNS||", all_dropdowns)

    index_template_string = index_template_string.replace("||SIDEBAR||", sidebar_string)

    print("writing to new index.html...")
    index_file = open("index.html", 'w')
    index_file.write(index_template_string)

    print("creating presentations...")
    revealjs_template = open("templates/revealjs_template", 'r').read()
    revealjs_video_template = open("templates/revealjs_video_section_template", 'r').read()
    for presentation in all_presentations:
        print(presentation)
        movie_files = []
        unprocessed_lines = open(presentation + "/partial_movie_file_list.txt").readlines()[1:]
        for l in unprocessed_lines:
            movie_files.append('/' + presentation + '/' + l.split('/')[-1].replace('\'', '').replace('\n', ''))
        
        video_sections = ""
        for v in movie_files:
            video_sections += revealjs_video_template.replace("||VIDEO_LINK||", v)
        
        open(presentation + '/entry.html', 'w').write(revealjs_template.replace("||SECTIONS||", video_sections))