fantaxy commited on
Commit
ee0bc84
ยท
verified ยท
1 Parent(s): cc7b568

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -13
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
- "id": BLOGGER_ID,
607
  "title": blog_title,
608
- "content": blog_content
609
  }
610
 
611
  try:
612
- # URL ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋ฐ None URL ์ฒ˜๋ฆฌ
613
- if "![๊ด€๋ จ ์ด๋ฏธ์ง€](None)" in blog_content:
614
- blog_content = blog_content.replace("![๊ด€๋ จ ์ด๋ฏธ์ง€](None)", "๊ด€๋ จ ์ด๋ฏธ์ง€๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
615
-
616
- payload["content"] = blog_content
617
-
618
- logger.debug(f"๋ธ”๋กœ๊ฑฐ์— ์ „์†กํ•  ํŽ˜์ด๋กœ๋“œ: {payload}")
619
 
620
  response = requests.post(WEBHOOK_URL, json=payload)
621
- logger.debug(f"๋ธ”๋กœ๊ฑฐ ์‘๋‹ต: {response.status_code}, {response.text}")
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(f"๋ธ”๋กœ๊ฑฐ์— ์ „์†ก ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
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(f"์ œ๋ชฉ '{title}' ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
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}")