Skip to content

Commit 2a77047

Browse files
authored
Merge pull request #489 from sparcs-kaist/fix/meal_crawler_salad
2 parents 7dca835 + 3030d59 commit 2a77047

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

apps/core/management/scripts/meal_crawler.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,29 @@ def _parser_east1_course(menu_list : str, time : int):
134134
Menu = list(filter(lambda x: x != '' and x != ' ' and x != '\n', Menu))
135135
Menu = list(filter(lambda x: '하루과일' not in x and '글로벌' not in x , Menu))
136136

137+
#2025-05-09 - 동맛골 1층 카페테리아가 식기세척기 고장으로 인해 운영하지 않음
138+
#이때 '미운영' 이라는 텍스트가 포함되어 있었음.
139+
137140
#모든 메뉴가 100원 단위. -> '00원' 이라는 텍스트가 포함된 부분을 찾으면 어디인지 알 수 있다.
138141
#이걸 기준으로 각 코스를 나누면 된다.
139142
Courses = {}
143+
#2025.05 샐러드 메뉴 등장 - 샐러드 처리 로직
144+
offset = 0
145+
for line in Menu:
146+
if '샐러드' in line:
147+
offset += 1
148+
else:
149+
break
150+
#샐러드 메뉴정보 -> 제거
151+
for _ in range(offset):
152+
Menu.pop(0)
153+
140154
for txt in Menu:
141155
#하루과일 : 파싱 x
142156
if '하루과일' in txt:
143157
break #하루과일은 항상 맨 마지막에 있다.
158+
if '미운영' in txt:
159+
break #어떤 이유로 식당이 운영하지 않는경우
144160
#코스 이름이 나온 경우
145161
if ('00원' in txt) or ('<' in txt and '>' in txt): #카페테리아 메뉴까지 같이 처리하기 위해 조건 추가.
146162
txt_match = re.match(r"<(.+?) (\d+,?\d*)원>", txt.strip()) #코스 이름과 가격은 <> 안에
@@ -175,9 +191,21 @@ def _parser_east1_cafeteria(menu_list : str, time : int) -> list:
175191
Menu = list(filter(lambda x: x != '' and x != ' ' and x != '\n', Menu))
176192
Menus = []
177193

194+
178195
#토/일요일 같이 영업 안하는 경우.
179196
if len(Menu) == 0:
180197
return {}
198+
199+
#2025.05 샐러드 메뉴 등장 - 샐러드 처리 로직
200+
offset = 0
201+
for line in Menu:
202+
if '샐러드' in line:
203+
offset += 1
204+
else:
205+
break
206+
#샐러드 메뉴정보 -> 제거
207+
for _ in range(offset):
208+
Menu.pop(0)
181209

182210
#카페테리아가 영업하지 않는 날
183211
if '<Cafeteria>' not in Menu.pop(0):
@@ -193,6 +221,7 @@ def _parser_east1_cafeteria(menu_list : str, time : int) -> list:
193221
allergy_list = [int(num) for num in allergy.split(",")] if allergy else [] # 숫자 목록을 리스트로 변환
194222
price = int(txt_match.group(3).replace(",", "")) # 쉼표 제거 후 가격 정수 변환
195223
Menus.append({'menu_name' : menu_name, 'price' : price, 'allergy' : allergy_list})
224+
print(f"최종 결과 : {Menus}")
196225
return Menus
197226

198227
else:
@@ -212,6 +241,18 @@ def _parser_east2(menu_list : str, time : int):
212241
return {}
213242
if '미운영' in Menu[0]:
214243
return {}
244+
245+
#2025-05 샐러드 메뉴 등장 - 샐러드 처리 로직. (샐러드는 항상 맨 윗줄에 있고, 각 줄별로 샐러드 라는 단어 나옴).
246+
offset = 0
247+
for line in Menu:
248+
if '샐러드' in line:
249+
offset += 1
250+
else:
251+
break
252+
#샐러드 메뉴정보 -> 제거
253+
for _ in range(offset):
254+
Menu.pop(0)
255+
215256

216257
Courses = {}
217258
for txt in Menu:
@@ -222,6 +263,7 @@ def _parser_east2(menu_list : str, time : int):
222263
break
223264
#코스 이름이 나온 경우 - 동맛골 2층은 '<>'로 가격이 둘러쌓여 있음.
224265
if '00원' in txt:
266+
print(txt)
225267
txt_match = re.match(r"<(.+?) (\d+,?\d*)원>", txt.strip())
226268
course_name = txt_match.group(1)
227269
course_price = int(txt_match.group(2).replace(",", ""))
@@ -413,7 +455,6 @@ def crawl_daily_meal(date : str):
413455
pipe.json().set(course_key ,'.', course_meal)
414456
pipe.execute()
415457

416-
print("celery가 일하고 있어요!")
417458
return
418459

419460

0 commit comments

Comments
 (0)