-
Notifications
You must be signed in to change notification settings - Fork 0
[Fix] 공지사항 크롤링 오류 #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,6 @@ | |
| settings = get_settings() | ||
| client = OpenAI(api_key=settings.openai_api_key) | ||
|
|
||
|
|
||
| def _to_text(value) -> str: | ||
| if value is None: | ||
| return "" | ||
|
|
@@ -26,16 +25,52 @@ def _to_text(value) -> str: | |
| return str(value) | ||
|
|
||
|
|
||
| def _format_schedule_info(value) -> str: | ||
| if value is None: | ||
| return "" | ||
|
|
||
| if isinstance(value, str): | ||
| return value.strip() | ||
|
|
||
| if isinstance(value, list): | ||
| return "\n".join(text for item in value if (text := _format_schedule_info(item))) | ||
|
|
||
| if isinstance(value, dict): | ||
| dormitory = _to_text(value.get("dormitory") or value.get("생활관")) | ||
| time = _to_text(value.get("time") or value.get("시간")) | ||
| if dormitory and time: | ||
| return f"{dormitory} {time}" | ||
|
|
||
| return "\n".join(text for val in value.values() if (text := _format_schedule_info(val))) | ||
|
|
||
| return str(value) | ||
|
|
||
|
|
||
| def _format_caution_info(value) -> str: | ||
| return _to_text(value) | ||
|
Comment on lines
+49
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
def _format_caution_info(value) -> str:
if value is None:
return ""
if isinstance(value, str):
return value.strip()
if isinstance(value, list):
return "\n".join(text for item in value if (text := _format_caution_info(item)))
if isinstance(value, dict):
return "\n".join(text for val in value.values() if (text := _format_caution_info(val)))
return str(value) |
||
|
|
||
|
|
||
| def summarize_notice(title: str, content: str) -> NoticeSummaryData: | ||
| settings = get_settings() | ||
| prompt = f""" | ||
| 다음 공지사항을 읽고 JSON만 반환해줘. | ||
|
|
||
| 반드시 아래 키를 포함해: | ||
| - summary: 2~4문장 핵심 요약 | ||
| - summary: 3~6문장 핵심만 요약 | ||
| - target_info: 대상자 정보가 있으면 정리, 없으면 null | ||
| - schedule_info: 주요 일정 정보가 있으면 정리, 없으면 null | ||
| - caution_info: 유의사항 정보가 있으면 정리, 없으면 null | ||
| - schedule_info: 주요 일정 정보가 있으면 문자열로 정리, 없으면 null | ||
| - caution_info: 유의사항 정보가 있으면 문자열로 정리, 없으면 null | ||
|
|
||
| schedule_info 작성 규칙: | ||
| - 반드시 문자열 또는 null로 반환해. 객체나 배열로 반환하지 마. | ||
| - date, details 같은 키 이름을 내용에 포함하지 마. | ||
| - 요일과 시간만 적어. 양식은 ####년 ##월 ##일, 시간은 오전 또는 오후 #시 이렇게. | ||
| - 생활관 별로 시간이 다르면 생활간 별 시간으로 적어. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| caution_info 작성 규칙: | ||
| - 반드시 문자열 또는 null로 반환해. 객체나 배열로 반환하지 마. | ||
| - caution, warning 같은 키 이름을 내용에 포함하지 마. | ||
| - 불이익, 제출 방법, 준비물, 제한사항처럼 사용자가 주의해야 할 내용만 넣어. | ||
|
|
||
| 제목: | ||
| {title} | ||
|
|
@@ -59,7 +94,7 @@ def summarize_notice(title: str, content: str) -> NoticeSummaryData: | |
| return NoticeSummaryData( | ||
| summary=_to_text(payload.get("summary")), | ||
| target_info=_to_text(payload.get("target_info")), | ||
| schedule_info=_to_text(payload.get("schedule_info")), | ||
| caution_info=_to_text(payload.get("caution_info")), | ||
| schedule_info=_format_schedule_info(payload.get("schedule_info")), | ||
| caution_info=_format_caution_info(payload.get("caution_info")), | ||
| generated_model=response.model, | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 구현된
_extract_detail_text_lines로직은 데이터 유실 위험이 있습니다.element.find(DETAIL_TEXT_BLOCK_TAGS)를 통해 자식 블록 요소가 있는 부모 요소를 건너뛰게 되면, 부모 요소의 직접적인 자식인 텍스트 노드들이 무시됩니다.예를 들어
<div>본문 시작 <p>중간 내용</p> 본문 끝</div>과 같은 구조에서 "본문 시작"과 "본문 끝"은 유실되고 "중간 내용"만 추출됩니다. 블록 요소들에 명시적으로 개행 문자를 삽입한 뒤 텍스트를 추출하는 방식이 더 안전하고 의도한 대로 인라인 태그들을 합칠 수 있습니다.