diff --git a/main.py b/main.py new file mode 100644 index 0000000..9b52362 --- /dev/null +++ b/main.py @@ -0,0 +1,4 @@ +import package as pkg + + +url = pkg.get_url.fetch_data_from_mariadb() \ No newline at end of file diff --git a/package/GetConfig.py b/package/GetConfig.py new file mode 100644 index 0000000..de93462 --- /dev/null +++ b/package/GetConfig.py @@ -0,0 +1,30 @@ +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') \ No newline at end of file diff --git a/package/__init__.py b/package/__init__.py new file mode 100644 index 0000000..8ba67e1 --- /dev/null +++ b/package/__init__.py @@ -0,0 +1 @@ +from . import get_url \ No newline at end of file diff --git a/convert_md.py b/package/convert_md.py similarity index 90% rename from convert_md.py rename to package/convert_md.py index 30c36e9..f94cf98 100644 --- a/convert_md.py +++ b/package/convert_md.py @@ -1,8 +1,8 @@ import os from dotenv import load_dotenv import markdown -import translate_article as ta -import open_ai as oa +import package.translate_article as ta +import ../openai/open_ai as oa # .env 파일에서 API 키 로드 load_dotenv(r'./.env.dev') diff --git a/get_url.py b/package/get_url.py similarity index 79% rename from get_url.py rename to package/get_url.py index cbee189..6c259b5 100644 --- a/get_url.py +++ b/package/get_url.py @@ -1,14 +1,7 @@ import mysql.connector -from dotenv import load_dotenv import os -# .env.demo 파일 로드 -load_dotenv(r'./.env.dev') -# 환경 변수 가져오기 -host = os.getenv('DB_HOST') -user = os.getenv('DB_USER') -password = os.getenv('DB_PASSWORD') -database = os.getenv('DB_NAME') + # MariaDB에 연결하는 함수 def fetch_data_from_mariadb(): try: diff --git a/open_ai.py b/package/open_ai.py similarity index 97% rename from open_ai.py rename to package/open_ai.py index 42e2360..ea9a03e 100644 --- a/open_ai.py +++ b/package/open_ai.py @@ -1,7 +1,7 @@ import os from openai import OpenAI from dotenv import load_dotenv -import translate_article as ta +import package.translate_article as ta # .env 파일에서 API 키 로드 load_dotenv() diff --git a/translate_article.py b/package/translate_article.py similarity index 96% rename from translate_article.py rename to package/translate_article.py index dd26388..3245de8 100644 --- a/translate_article.py +++ b/package/translate_article.py @@ -1,6 +1,6 @@ import requests from bs4 import BeautifulSoup -import get_url +import db_ctr.get_url as get_url url = get_url.fetch_data_from_mariadb()['url'] diff --git a/wp.py b/package/wp.py similarity index 100% rename from wp.py rename to package/wp.py