From 4d1fd7a5be849915321318e641f89119b870cd54 Mon Sep 17 00:00:00 2001 From: icurfer Date: Thu, 3 Oct 2024 08:32:03 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 4 +++ package/GetConfig.py | 30 +++++++++++++++++++ package/__init__.py | 1 + convert_md.py => package/convert_md.py | 4 +-- get_url.py => package/get_url.py | 9 +----- open_ai.py => package/open_ai.py | 2 +- .../translate_article.py | 2 +- wp.py => package/wp.py | 0 8 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 main.py create mode 100644 package/GetConfig.py create mode 100644 package/__init__.py rename convert_md.py => package/convert_md.py (90%) rename get_url.py => package/get_url.py (79%) rename open_ai.py => package/open_ai.py (97%) rename translate_article.py => package/translate_article.py (96%) rename wp.py => package/wp.py (100%) 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