requirements.txt 추가 및 lib.py > common.py 수정과 리팩토링

This commit is contained in:
2025-07-14 13:14:38 +09:00
parent e396c08f6b
commit 72a12ac29f
4 changed files with 15 additions and 8 deletions

View File

@ -14,7 +14,7 @@ from conf.config import (
MESSAGE_PLATFORMS, MATTERMOST_URL, MATTERMOST_BOT_TOKEN, MATTERMOST_CHANNEL_ID MESSAGE_PLATFORMS, MATTERMOST_URL, MATTERMOST_BOT_TOKEN, MATTERMOST_CHANNEL_ID
) )
from lib.send_message import MessageSender from lib.send_message import MessageSender
from lib.lib import ( from lib.common import (
create_mobile_driver, create_mobile_driver,
save_cookies, save_cookies,
load_cookies, load_cookies,
@ -92,11 +92,13 @@ class NaverReviewCollector:
for i in range(4, 7): for i in range(4, 7):
try: try:
el = li.find_element(By.XPATH, f"./div[{i}]/a") el = li.find_element(By.XPATH, f"./div[{i}]/a")
if el and el.text.strip(): if el:
return clean_html_text(el.get_attribute("innerHTML")) text = el.text.strip()
return clean_html_text(el.get_attribute("innerHTML")) if text else "내용 없음"
except Exception: except Exception:
continue continue
return None return "내용 없음"
def extract_reviews(self): def extract_reviews(self):
reviews = [] reviews = []
@ -132,8 +134,8 @@ class NaverReviewCollector:
continue continue
text = self.extract_review_text(li) text = self.extract_review_text(li)
if not text: #if not text:
continue # continue
reviews.append({ reviews.append({
"작성자": author, "작성자": author,
@ -241,13 +243,14 @@ class NaverReviewCollector:
self.reviews_by_place[place_name] = [] self.reviews_by_place[place_name] = []
self.driver.quit() self.driver.quit()
if not self.reviews_by_place: if not self.reviews_by_place:
sender = MessageSender( sender = MessageSender(
mattermost_url=MATTERMOST_URL, mattermost_url=MATTERMOST_URL,
mattermost_token=MATTERMOST_BOT_TOKEN, mattermost_token=MATTERMOST_BOT_TOKEN,
mattermost_channel_id=MATTERMOST_CHANNEL_ID, mattermost_channel_id=MATTERMOST_CHANNEL_ID,
) )
send_failure_message(sender, MESSAGE_PLATFORMS) send_failure_message(sender, MESSAGE_PLATFORMS)
else: else:
self.send_to_message() self.send_to_message()

View File

@ -12,7 +12,7 @@ from conf.config import (
MESSAGE_PLATFORMS, MATTERMOST_URL, MATTERMOST_BOT_TOKEN, MATTERMOST_CHANNEL_ID MESSAGE_PLATFORMS, MATTERMOST_URL, MATTERMOST_BOT_TOKEN, MATTERMOST_CHANNEL_ID
) )
from lib.send_message import MessageSender from lib.send_message import MessageSender
from lib.lib import ( from lib.common import (
create_mobile_driver, create_mobile_driver,
get_start_end_dates, get_start_end_dates,
parse_korean_date, parse_korean_date,

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
selenium
requests
undetected_chromedriver
dotenv