forked from EDHD2025HEIG/Data_cleanUp_step1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (52 loc) · 1.61 KB
/
main.py
File metadata and controls
64 lines (52 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
"""
main.py – Application entry point
"""
import os
import sys
import logging
from dotenv import load_dotenv
from typing import Optional
# ---------------------------
# Configuration & Logging
# ---------------------------
def setup_logging(level: int = logging.INFO) -> None:
"""Configure basic logging."""
logging.basicConfig(
level=level,
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
def load_config() -> None:
"""Load environment variables from a .env file if present."""
load_dotenv()
logging.info("Environment variables loaded.")
# ---------------------------
# Core Logic
# ---------------------------
def main(args: Optional[list[str]] = None) -> None:
"""
Main entry point of the application.
:param args: Optional list of arguments (defaults to sys.argv[1:])
"""
if args is None:
args = sys.argv[1:]
logging.info("Application started with arguments: %s", args)
try:
# Your application logic here
logging.info("Running main application logic...")
print("Hello, world! 👋")
# Example: Access an environment variable
my_var = os.getenv("MY_VARIABLE", "default_value")
logging.info(f"MY_VARIABLE = {my_var}")
except Exception as e:
logging.exception("An unexpected error occurred: %s", e)
sys.exit(1)
logging.info("Application finished successfully.")
# ---------------------------
# Script Entry
# ---------------------------
if __name__ == "__main__":
setup_logging()
load_config()
main()