Update app.py
Browse files
app.py
CHANGED
|
@@ -45,37 +45,40 @@ def add_watermark(image, text="gooditem gooditem gooditem gooditem gooditem"):
|
|
| 45 |
combined = Image.alpha_composite(image.convert('RGBA'), watermark)
|
| 46 |
return combined
|
| 47 |
|
| 48 |
-
|
| 49 |
def extract_info_block(article_text):
|
| 50 |
pattern = r'(KBS2.*?<๋ชจ๋ธ๋ช
>.*?)(?:\n\n|$)'
|
| 51 |
match = re.search(pattern, article_text, re.DOTALL)
|
|
|
|
| 52 |
if match:
|
| 53 |
return match.group(1).strip()
|
| 54 |
else:
|
| 55 |
return None
|
| 56 |
|
| 57 |
-
#
|
|
|
|
| 58 |
def extract_product_info(article_text):
|
| 59 |
brand_match = re.search(r'<๋ธ๋๋>[ \t]*([^\n]+)', article_text)
|
| 60 |
-
model_matches = re.findall(r'<๋ชจ๋ธ๋ช
>[ \t]*([^\n]+)', article_text)
|
| 61 |
-
|
| 62 |
brand = brand_match.group(1).strip() if brand_match else None
|
| 63 |
-
|
|
|
|
| 64 |
|
| 65 |
result = []
|
| 66 |
|
| 67 |
-
if brand and
|
| 68 |
brand_words = re.findall(r'[A-Za-z]+', brand)
|
| 69 |
-
selected_brand = ' '.join(brand_words[:2])
|
| 70 |
|
| 71 |
-
for model in
|
|
|
|
| 72 |
search_query = f"{selected_brand} {model}"
|
| 73 |
search_url = f"https://www.coupang.com/np/search?component=&q={search_query.replace(' ', '+')}"
|
| 74 |
result.append((model, search_url))
|
| 75 |
-
|
| 76 |
return result
|
| 77 |
|
| 78 |
-
#
|
|
|
|
| 79 |
def process_url(tistory_url, output_dir):
|
| 80 |
result = []
|
| 81 |
try:
|
|
@@ -85,6 +88,7 @@ def process_url(tistory_url, output_dir):
|
|
| 85 |
img_tags = soup.find_all('img')
|
| 86 |
img_urls = [img['src'] for img in img_tags if 'src' in img.attrs]
|
| 87 |
|
|
|
|
| 88 |
for idx, img_url in enumerate(img_urls):
|
| 89 |
base_name = os.path.basename(img_url).split('?')[0]
|
| 90 |
if base_name.startswith('new_ico'):
|
|
@@ -104,31 +108,33 @@ def process_url(tistory_url, output_dir):
|
|
| 104 |
name, ext = os.path.splitext(base_name)
|
| 105 |
save_path = os.path.join(output_dir, f"{name}_{idx+1}_processed.png")
|
| 106 |
final_img.save(save_path)
|
|
|
|
| 107 |
|
| 108 |
-
|
| 109 |
-
relative_path = save_path.replace("./", "/")
|
| 110 |
-
result.append(f"๐ผ๏ธ [์ด๋ฏธ์ง ๋ค์ด๋ก๋]({relative_path})")
|
| 111 |
-
|
| 112 |
article_text = soup.get_text()
|
| 113 |
|
|
|
|
| 114 |
info_block = extract_info_block(article_text)
|
| 115 |
-
product_infos = extract_product_info(article_text)
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
if info_block:
|
| 118 |
result.append("\n===== ํ๋ก๊ทธ๋จ ์ ๋ณด ๋ธ๋ก =====")
|
| 119 |
result.append(info_block)
|
| 120 |
result.append("================================\n")
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
result.append(f"๐ ์ฟ ํก ๋งํฌ: {search_url}")
|
| 126 |
|
| 127 |
except Exception as e:
|
| 128 |
result.append(f"โ URL ์ฒ๋ฆฌ ์คํจ: {tistory_url} / ์๋ฌ: {e}")
|
| 129 |
|
| 130 |
return result
|
| 131 |
|
|
|
|
| 132 |
# ์ฌ๋ฌ URL ์ฒ๋ฆฌ
|
| 133 |
def process_multiple_urls(urls_text, output_dir):
|
| 134 |
urls = [url.strip() for url in urls_text.strip().splitlines() if url.strip()]
|
|
|
|
| 45 |
combined = Image.alpha_composite(image.convert('RGBA'), watermark)
|
| 46 |
return combined
|
| 47 |
|
| 48 |
+
|
| 49 |
def extract_info_block(article_text):
|
| 50 |
pattern = r'(KBS2.*?<๋ชจ๋ธ๋ช
>.*?)(?:\n\n|$)'
|
| 51 |
match = re.search(pattern, article_text, re.DOTALL)
|
| 52 |
+
|
| 53 |
if match:
|
| 54 |
return match.group(1).strip()
|
| 55 |
else:
|
| 56 |
return None
|
| 57 |
|
| 58 |
+
# ์ ํ๋ช
์ถ์ถ ํจ์ ์์ (์ฌ๋ฌ ๋ชจ๋ธ๋ช
์ฒ๋ฆฌ)
|
| 59 |
+
|
| 60 |
def extract_product_info(article_text):
|
| 61 |
brand_match = re.search(r'<๋ธ๋๋>[ \t]*([^\n]+)', article_text)
|
|
|
|
|
|
|
| 62 |
brand = brand_match.group(1).strip() if brand_match else None
|
| 63 |
+
|
| 64 |
+
model_matches = re.findall(r'<๋ชจ๋ธ๋ช
>[ \t]*([^\n]+)', article_text)
|
| 65 |
|
| 66 |
result = []
|
| 67 |
|
| 68 |
+
if brand and model_matches:
|
| 69 |
brand_words = re.findall(r'[A-Za-z]+', brand)
|
| 70 |
+
selected_brand = ' '.join(brand_words[:2])
|
| 71 |
|
| 72 |
+
for model in model_matches:
|
| 73 |
+
model = model.strip()
|
| 74 |
search_query = f"{selected_brand} {model}"
|
| 75 |
search_url = f"https://www.coupang.com/np/search?component=&q={search_query.replace(' ', '+')}"
|
| 76 |
result.append((model, search_url))
|
| 77 |
+
|
| 78 |
return result
|
| 79 |
|
| 80 |
+
# process_url ํจ์ ์์ (๋ชจ๋ธ๋ช
์ฌ๋ฌ๊ฐ ๋์)
|
| 81 |
+
|
| 82 |
def process_url(tistory_url, output_dir):
|
| 83 |
result = []
|
| 84 |
try:
|
|
|
|
| 88 |
img_tags = soup.find_all('img')
|
| 89 |
img_urls = [img['src'] for img in img_tags if 'src' in img.attrs]
|
| 90 |
|
| 91 |
+
# ์ด๋ฏธ์ง ์ฒ๋ฆฌ
|
| 92 |
for idx, img_url in enumerate(img_urls):
|
| 93 |
base_name = os.path.basename(img_url).split('?')[0]
|
| 94 |
if base_name.startswith('new_ico'):
|
|
|
|
| 108 |
name, ext = os.path.splitext(base_name)
|
| 109 |
save_path = os.path.join(output_dir, f"{name}_{idx+1}_processed.png")
|
| 110 |
final_img.save(save_path)
|
| 111 |
+
result.append(f"โ๏ธ ์ ์ฅ ์๋ฃ: {save_path}")
|
| 112 |
|
| 113 |
+
# ํ
์คํธ ์ถ์ถ
|
|
|
|
|
|
|
|
|
|
| 114 |
article_text = soup.get_text()
|
| 115 |
|
| 116 |
+
# ํ๋ก๊ทธ๋จ ์ ๋ณด ๋ธ๋ก ์ถ์ถ
|
| 117 |
info_block = extract_info_block(article_text)
|
|
|
|
| 118 |
|
| 119 |
+
# ์ ํ ์ ๋ณด ์ถ์ถ (์ฌ๋ฌ ๋ชจ๋ธ๋ช
์ฒ๋ฆฌ)
|
| 120 |
+
item_info_list = extract_product_info(article_text)
|
| 121 |
+
|
| 122 |
+
# ์ ๋ฆฌ๋ ์ถ๋ ฅ ํฌ๋งท
|
| 123 |
if info_block:
|
| 124 |
result.append("\n===== ํ๋ก๊ทธ๋จ ์ ๋ณด ๋ธ๋ก =====")
|
| 125 |
result.append(info_block)
|
| 126 |
result.append("================================\n")
|
| 127 |
|
| 128 |
+
for model_name, search_url in item_info_list:
|
| 129 |
+
result.append(f"๐๏ธ ์์ดํ
: {model_name}")
|
| 130 |
+
result.append(f"๐ ์ฟ ํก ๋งํฌ: {search_url}")
|
|
|
|
| 131 |
|
| 132 |
except Exception as e:
|
| 133 |
result.append(f"โ URL ์ฒ๋ฆฌ ์คํจ: {tistory_url} / ์๋ฌ: {e}")
|
| 134 |
|
| 135 |
return result
|
| 136 |
|
| 137 |
+
|
| 138 |
# ์ฌ๋ฌ URL ์ฒ๋ฆฌ
|
| 139 |
def process_multiple_urls(urls_text, output_dir):
|
| 140 |
urls = [url.strip() for url in urls_text.strip().splitlines() if url.strip()]
|