node -> python 변경 진행중
This commit is contained in:
commit
660f85f145
5 changed files with 285 additions and 0 deletions
63
menu.py
Normal file
63
menu.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# menu repository
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Dict, Final, List, Optional
|
||||
import requests
|
||||
|
||||
import slack
|
||||
|
||||
BASE: Final[str] = 'https://sfmn.shinsegaefood.com/'
|
||||
URL: Final[str] = f'{BASE}selectTodayMenu2.do'
|
||||
HEADER: Final[Dict[str, str]] = {
|
||||
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Mobile/15E148 Safari/604.1',
|
||||
'Content-Type': 'application/json',
|
||||
'Referer': 'https://sfmn.shinsegaefood.com/selectTodayMenu.do',
|
||||
}
|
||||
STORE: Final[str] = '06379'
|
||||
|
||||
@dataclass
|
||||
class Menu:
|
||||
meal_time: str
|
||||
meal_type: str
|
||||
rep_menu: str
|
||||
detailed_menu: str
|
||||
calory: str
|
||||
menu_image: Optional[str]
|
||||
|
||||
def __post_init__(self):
|
||||
if self.menu_image:
|
||||
self.menu_image = f"https://store.shinsegaefood.com/{self.menu_image}"
|
||||
|
||||
def to_slack_block(self, date: str) -> Dict[str, Any]:
|
||||
blocks = [slack.markdown(f'*{date} 일자 메뉴*')]
|
||||
return {}
|
||||
|
||||
# date should be this form 20240601
|
||||
def menu(date: str) -> List[Menu]:
|
||||
menus: List[Menu] = []
|
||||
res = requests.post(URL, headers=HEADER, json={
|
||||
'menuDate': date,
|
||||
'storeCd': STORE,
|
||||
'cafeCd': '01',
|
||||
'dispBaseCd': '0',
|
||||
'userLang': 'K'
|
||||
})
|
||||
if res.status_code != 200:
|
||||
return menus
|
||||
data: List[Dict[str, str]] = []
|
||||
try:
|
||||
data = res.json()['model']['model']
|
||||
except:
|
||||
return menus
|
||||
for each in data:
|
||||
try:
|
||||
menus.append(Menu(
|
||||
each['MEAL_TYPE_NM'],
|
||||
each['DINNER_TYPE_NM'],
|
||||
each['REP_TYPE_NM'],
|
||||
each['MENU_DESC'],
|
||||
each['TOT_CALORY'],
|
||||
each.get('MEAL_TYPE_NM'),
|
||||
))
|
||||
except:
|
||||
pass
|
||||
return menus
|
||||
Loading…
Add table
Add a link
Reference in a new issue