wp-post-automation/main.py

38 lines
1.1 KiB
Python

import package as pkg
from package import GetConfig, MariaDB, ChangeTextToPost, WordPress
import markdown
# 2024-10-03 환경 변수 호출
config = GetConfig()
dict_data = config.get_config_as_dict()
# 2024-10-03 db에서 url정보 호출
db = MariaDB(dict_data)
url = db.fetch_data_from_mariadb()['url']
# 2024-10-03 url을 이용해서 text추출
origin_content = pkg.getContents(url)
# 2024-10-03 openAI를 이용하여 게시글 스타일 변경
openai_key = dict_data['openai_api_key']
wp_reference_style = dict_data['wp_post_style']
open_ai = ChangeTextToPost(openai_key)
post_article = open_ai.generate_blog_post(origin_content, wp_reference_style)
# 2024-10-03 Markdown을 HTML로 변환
html = markdown.markdown(post_article)
# 2024-10-03 워드프레스 포스팅 임시등록
wp = WordPress(dict_data)
rs = wp.create_post(2,html)
if __name__ == "__main__":
# print(post_article)
print("추가 확인을 위한 출력")
if rs.ok:
print(f"성공 code:{rs.status_code}")
else:
print(f"실패 code:{rs.status_code} reason:{rs.reason} msg:{rs.text}")