Update app.py
Browse files
app.py
CHANGED
@@ -601,31 +601,43 @@ def get_image_url(topic):
|
|
601 |
logger.error(f"์ด๋ฏธ์ง ๊ฒ์ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
602 |
return None
|
603 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
604 |
def send_to_blogger(blog_title, blog_content):
|
|
|
|
|
|
|
605 |
payload = {
|
606 |
-
"
|
607 |
"title": blog_title,
|
608 |
-
"content":
|
609 |
}
|
610 |
|
611 |
try:
|
612 |
-
|
613 |
-
if "" in blog_content:
|
614 |
-
blog_content = blog_content.replace("", "๊ด๋ จ ์ด๋ฏธ์ง๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.")
|
615 |
-
|
616 |
-
payload["content"] = blog_content
|
617 |
-
|
618 |
-
logger.debug(f"๋ธ๋ก๊ฑฐ์ ์ ์กํ ํ์ด๋ก๋: {payload}")
|
619 |
|
620 |
response = requests.post(WEBHOOK_URL, json=payload)
|
621 |
-
logger.debug(
|
622 |
|
623 |
if response.status_code == 200:
|
624 |
return "ํฌ์คํ
์ด ์ฑ๊ณต์ ์ผ๋ก ์ ์ก๋์์ต๋๋ค."
|
625 |
else:
|
626 |
return f"ํฌ์คํ
์ ์ก ์คํจ. ์ํ ์ฝ๋: {response.status_code}"
|
627 |
except Exception as e:
|
628 |
-
logger.error(
|
629 |
return f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
630 |
|
631 |
def process_all_titles(category, style, topic, num_titles):
|
@@ -655,13 +667,12 @@ def process_all_titles(category, style, topic, num_titles):
|
|
655 |
|
656 |
results.append(f"์ ๋ชฉ: {title}\n์ ์ก ๊ฒฐ๊ณผ: {send_result}\n์ฌ์ฉ๋ ์ด๋ฏธ์ง URL: {image_url if image_url else '์ด๋ฏธ์ง ์์'}\n\n")
|
657 |
except Exception as e:
|
658 |
-
logger.error(
|
659 |
results.append(f"์ ๋ชฉ: {title}\n์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}\n\n")
|
660 |
|
661 |
time.sleep(5) # API ํธ์ถ ์ฌ์ด์ 5์ด ๋๊ธฐ
|
662 |
|
663 |
return "\n".join(results)
|
664 |
-
|
665 |
|
666 |
with gr.Blocks() as demo:
|
667 |
gr.Markdown(f"# {title}")
|
|
|
601 |
logger.error(f"์ด๋ฏธ์ง ๊ฒ์ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
602 |
return None
|
603 |
|
604 |
+
def convert_markdown_images(content):
|
605 |
+
logger.debug("์๋ณธ ๋ด์ฉ: %s", content)
|
606 |
+
|
607 |
+
# Markdown ์ด๋ฏธ์ง ๋ฌธ๋ฒ์ HTML <img> ํ๊ทธ๋ก ๋ณํ
|
608 |
+
markdown_pattern = r'!\[([^\]]*)\]\(([^)]+)\)'
|
609 |
+
content = re.sub(markdown_pattern, r'<img alt="\1" src="\2">', content)
|
610 |
+
|
611 |
+
# ๋จ์ URL์ <img> ํ๊ทธ๋ก ๋ณํ
|
612 |
+
url_pattern = r'(https?://\S+?\.(jpg|jpeg|png|gif))'
|
613 |
+
content = re.sub(url_pattern, r'<img src="\1">', content)
|
614 |
+
|
615 |
+
logger.debug("๋ณํ๋ ๋ด์ฉ: %s", content)
|
616 |
+
|
617 |
+
return content
|
618 |
+
|
619 |
def send_to_blogger(blog_title, blog_content):
|
620 |
+
converted_content = convert_markdown_images(blog_content)
|
621 |
+
logger.debug("๋ณํ๋ ๋ด์ฉ: %s", converted_content)
|
622 |
+
|
623 |
payload = {
|
624 |
+
"blogger_id": BLOGGER_ID,
|
625 |
"title": blog_title,
|
626 |
+
"content": converted_content
|
627 |
}
|
628 |
|
629 |
try:
|
630 |
+
logger.debug("๋ธ๋ก๊ฑฐ์ ์ ์กํ ํ์ด๋ก๋: %s", payload)
|
|
|
|
|
|
|
|
|
|
|
|
|
631 |
|
632 |
response = requests.post(WEBHOOK_URL, json=payload)
|
633 |
+
logger.debug("๋ธ๋ก๊ฑฐ ์๋ต: %s, %s", response.status_code, response.text)
|
634 |
|
635 |
if response.status_code == 200:
|
636 |
return "ํฌ์คํ
์ด ์ฑ๊ณต์ ์ผ๋ก ์ ์ก๋์์ต๋๋ค."
|
637 |
else:
|
638 |
return f"ํฌ์คํ
์ ์ก ์คํจ. ์ํ ์ฝ๋: {response.status_code}"
|
639 |
except Exception as e:
|
640 |
+
logger.error("๋ธ๋ก๊ฑฐ์ ์ ์ก ์ค ์ค๋ฅ ๋ฐ์: %s", str(e))
|
641 |
return f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
642 |
|
643 |
def process_all_titles(category, style, topic, num_titles):
|
|
|
667 |
|
668 |
results.append(f"์ ๋ชฉ: {title}\n์ ์ก ๊ฒฐ๊ณผ: {send_result}\n์ฌ์ฉ๋ ์ด๋ฏธ์ง URL: {image_url if image_url else '์ด๋ฏธ์ง ์์'}\n\n")
|
669 |
except Exception as e:
|
670 |
+
logger.error("์ ๋ชฉ '%s' ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: %s", title, str(e))
|
671 |
results.append(f"์ ๋ชฉ: {title}\n์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}\n\n")
|
672 |
|
673 |
time.sleep(5) # API ํธ์ถ ์ฌ์ด์ 5์ด ๋๊ธฐ
|
674 |
|
675 |
return "\n".join(results)
|
|
|
676 |
|
677 |
with gr.Blocks() as demo:
|
678 |
gr.Markdown(f"# {title}")
|