Skip to content

feat: Make static_site_generator.py a standalone script #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/static_site_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from jinja2 import Environment, FileSystemLoader
from rich import print
import json
import logging
import os

Expand All @@ -13,7 +15,7 @@ def __init__(self):
'tasks': []
}

def generate_site(self, data:list=None, projects:list[str]=None, output_file='./_site/index.html'):
def generate_site(self, data:list=None, projects:list[str]=None, output_file='./_site/index.html') -> None:
logging.info("Generating Static Site")
env = Environment(loader=FileSystemLoader('templates'))
template = env.get_template('kaban_board.html')
Expand All @@ -40,3 +42,19 @@ def generate_site(self, data:list=None, projects:list[str]=None, output_file='./
f.write(output)

logging.info("Static Site Generated @ ./_site/index.html")

def main():
ss_gen = StaticSiteGenerator()
data_file:str = input("Enter the path to the json file with data: ")
Comment on lines +47 to +48
Copy link
Preview

Copilot AI May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using argparse for handling command line arguments to improve user experience and provide more flexibility than interactive input.

Suggested change
ss_gen = StaticSiteGenerator()
data_file:str = input("Enter the path to the json file with data: ")
import argparse
parser = argparse.ArgumentParser(description="Generate a static site from a JSON data file.")
parser.add_argument("--data-file", required=True, help="Path to the JSON file with data.")
args = parser.parse_args()
ss_gen = StaticSiteGenerator()
data_file = args.data_file

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont want to

if not os.path.exists(data_file):
print(f"[bold red]File {data_file} does not exist.[/bold red]")
return

data:list = []
with open(data_file, 'r') as f:
data = json.load(f)
Comment on lines +54 to +55
Copy link
Preview

Copilot AI May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] It may be beneficial to wrap the JSON file loading in a try-except block to gracefully handle JSON decoding errors.

Suggested change
with open(data_file, 'r') as f:
data = json.load(f)
try:
with open(data_file, 'r') as f:
data = json.load(f)
except json.JSONDecodeError as e:
print(f"[bold red]Error: Failed to decode JSON from file {data_file}. Please check the file format.[/bold red]")
return

Copilot uses AI. Check for mistakes.


ss_gen.generate_site(data=data)

if __name__ == "__main__":
main()