diff --git a/README.md b/README.md index 8cc3419..cc50add 100644 --- a/README.md +++ b/README.md @@ -1 +1,6 @@ -# software_engineering_essentials \ No newline at end of file +# Software Engineering Principles +## Session #0 +1. Launch codespaces +2. Install libraries using requirements.txt - **Dependency Management** +3. Add json in “users” dir and serve locally +and create a new PR (checkout, add, commit, push) - **Git** \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1750fb2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +Flask==2.3.3 +snakeviz==2.2.0 +pytest==7.4.2 +pytest-cov==4.1.0 +yapf==0.40.2 +names==0.3.0 \ No newline at end of file diff --git a/server.py b/server.py new file mode 100644 index 0000000..62b085c --- /dev/null +++ b/server.py @@ -0,0 +1,77 @@ +from flask import Flask +import json, os +from typing import Dict, Any + +directory_path = "./users" + +app = Flask(__name__) + +styles = """ + +""" + +def read_json_files_from_directory(directory_path: str): + """ Read JSON files from provided path and return dict in format of {user_id:user_info}""" + json_data: Dict[str, Any] = {} + + try: + # Iterate through the files in the directory + for filename in os.listdir(directory_path): + if filename.endswith('.json'): + file_path = os.path.join(directory_path, filename) + with open(file_path, 'r') as file: + # Read and parse the JSON data + data = json.load(file) + for user_info in data: + json_data[user_info["user_id"]] = user_info + except FileNotFoundError: + print(f"Directory not found: {directory_path}") + return None + except json.JSONDecodeError as e: + print(f"Error decoding JSON: {e}") + return None + + return json_data + + +@app.route('/') +def get_users(): + """Renders a table of all users.""" + user_objs = read_json_files_from_directory(directory_path) + response = "" + for person_id in user_objs: + response += f"""