Created
February 25, 2024 18:47
-
-
Save jarebear6expepjozn6rakjq5iczi3irqwphcvb/3063b4ba26df89261824cb16c5e9dfc5 to your computer and use it in GitHub Desktop.
generate_html.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| media_root = "media" | |
| html_content_block = "" | |
| def format_dir_name(i): | |
| t = i.replace("_", " ").title() | |
| return t | |
| def format_file_name(i): | |
| t = i.split(".")[0].replace("_", " ").title() | |
| return t | |
| def html_generate_media_block(i): | |
| return """ | |
| <video width="320" height="240" controls="controls" preload="none"> | |
| <source src="{}" type="video/mp4" /> | |
| Your browser does not support the video tag. | |
| </video> | |
| """.format(i) | |
| def html_generate_article_block(i): | |
| return """ | |
| <article> | |
| <details> | |
| <summary> | |
| {} | |
| </summary> | |
| <p>{}</p> | |
| </details> | |
| </article> | |
| """.format(i[0], i[1]) | |
| def html_generate_h1_block(i): | |
| return """ | |
| <h1>{}</h1> | |
| """.format(i) | |
| dirs = os.listdir(media_root) | |
| for dir in dirs: | |
| dir_path = os.path.join(media_root, dir) | |
| html_content_block += html_generate_h1_block(format_dir_name(dir)) | |
| # step through files | |
| for file in sorted(os.listdir(dir_path)): | |
| media_path = os.path.join(dir_path, file) | |
| html_article_block = html_generate_article_block( | |
| [format_file_name(file), html_generate_media_block(media_path)] | |
| ) | |
| html_content_block += html_article_block | |
| f = open("index.html", "w") | |
| f.write(html_content_block) | |
| f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment