wp-post-automation/package/GetConfig.py
2024-10-03 08:32:03 +09:00

30 lines
907 B
Python

import os
from dotenv import load_dotenv
load_dotenv(r'./.env.dev')
class GetConfig:
def __init__(self):
self.host = os.getenv('DB_HOST')
self.user = os.getenv('DB_USER')
self.password = os.getenv('DB_PASSWORD')
self.database = os.getenv('DB_NAME')
def show_config(self):
for key, value in self.__dict__.items():
print(f"{key.upper()}: {value}")
if __name__ == "__main__":
# 결과 확인
config = GetConfig()
config.show_config()
# 오랜만에 보다보니 헷갈려서 참고용으로 작성
# class GetConfig:
# def __init__(self, name=None):
# self.name = name if name is not None else "default_name"
# self.host = os.getenv('DB_HOST')
# self.user = os.getenv('DB_USER')
# self.password = os.getenv('DB_PASSWORD')
# self.database = os.getenv('DB_NAME')