wp-post-automation/package/GetConfig.py

40 lines
1.3 KiB
Python

import os
from dotenv import load_dotenv
load_dotenv(r'./.env.dev')
class GetConfig:
def __init__(self):
self.db_host = os.getenv('DB_HOST')
self.db_user = os.getenv('DB_USER')
self.db_pw = os.getenv('DB_PASSWORD')
self.db_database = os.getenv('DB_NAME')
self.openai_api_key = os.getenv('OPENAI_API_KEY')
self.wp_url = os.getenv('WP_URL')
self.wp_user = os.getenv('WP_USER')
self.wp_api_key = os.getenv('WP_API_KEY')
self.wp_post_style = os.getenv('WP_POST_STYLE')
def show_config(self):
for key, value in self.__dict__.items():
print(f"{key.upper()}: {value}")
def get_config_as_dict(self):
# 인스턴스 속성을 딕셔너리로 반환
return self.__dict__
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')