slack 메시지 변환하는 부분 작성중
This commit is contained in:
parent
660f85f145
commit
91e986b475
3 changed files with 37 additions and 8 deletions
6
main.py
6
main.py
|
|
@ -50,10 +50,10 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> Dict[str, str]:
|
||||||
return PARAM_ERROR
|
return PARAM_ERROR
|
||||||
menus = menu.menu(param.date)
|
menus = menu.menu(param.date)
|
||||||
menus_without_img = [ x for x in menus if x.menu_image is None ]
|
menus_without_img = [ x for x in menus if x.menu_image is None ]
|
||||||
if len(menus) == 0:
|
if param.count < MAX_RETRY and (len(menus) == 0 or len(menus_without_img) > 0):
|
||||||
return retry(param, lambda_arn, schedule_role_arn)
|
return retry(param, lambda_arn, schedule_role_arn)
|
||||||
menus_without_img: List[menu.Menu] = [ x for x in menus if x.menu_image is None ]
|
if len(menus) == 0:
|
||||||
if len(menus_without_img) > 0 and param.count < MAX_RETRY:
|
# 슬랙 메시지 전송( 오늘의 메뉴 존재 X )
|
||||||
return retry(param, lambda_arn, schedule_role_arn)
|
return retry(param, lambda_arn, schedule_role_arn)
|
||||||
# Extract relevant data for your Slack message (adjust as needed)
|
# Extract relevant data for your Slack message (adjust as needed)
|
||||||
message_content: str = f"*Important Data from External API*\n"
|
message_content: str = f"*Important Data from External API*\n"
|
||||||
|
|
|
||||||
4
menu.py
4
menu.py
|
|
@ -27,10 +27,6 @@ class Menu:
|
||||||
if self.menu_image:
|
if self.menu_image:
|
||||||
self.menu_image = f"https://store.shinsegaefood.com/{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
|
# date should be this form 20240601
|
||||||
def menu(date: str) -> List[Menu]:
|
def menu(date: str) -> List[Menu]:
|
||||||
menus: List[Menu] = []
|
menus: List[Menu] = []
|
||||||
|
|
|
||||||
35
slack.py
35
slack.py
|
|
@ -1,4 +1,5 @@
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict, List
|
||||||
|
from menu import Menu
|
||||||
|
|
||||||
def markdown(text: str) -> Dict[str, Any]:
|
def markdown(text: str) -> Dict[str, Any]:
|
||||||
return {
|
return {
|
||||||
|
|
@ -8,3 +9,35 @@ def markdown(text: str) -> Dict[str, Any]:
|
||||||
'text': text
|
'text': text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def img(text: str, img_url: str) -> Dict[str, Any]:
|
||||||
|
return {
|
||||||
|
'type': 'image',
|
||||||
|
'title': {
|
||||||
|
'type': 'plain_text',
|
||||||
|
'text': text
|
||||||
|
},
|
||||||
|
'image_url': img_url,
|
||||||
|
'alt_text': text
|
||||||
|
}
|
||||||
|
|
||||||
|
def menu_to_str(m: Menu) -> str:
|
||||||
|
ret = '\n'.join([
|
||||||
|
f'*식사 시간*: {m.meal_time}',
|
||||||
|
f'*식사 종류*: {m.meal_type}',
|
||||||
|
f'*대표 메뉴*: {m.rep_menu}',
|
||||||
|
f'*상세 메뉴*: {m.detailed_menu}',
|
||||||
|
f'*칼로리*: {m.calory}',
|
||||||
|
])
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def for_slack(date: str, data: List[Menu]) -> Dict[str, Any]:
|
||||||
|
blocks = [markdown(f'*{date} 일자 메뉴*')]
|
||||||
|
for each in data:
|
||||||
|
blocks.append(markdown(menu_to_str(each)))
|
||||||
|
if each.menu_image:
|
||||||
|
blocks.append(img(each.rep_menu, each.menu_image))
|
||||||
|
else:
|
||||||
|
blocks.append(markdown('이미지가 존재하지 않습니다'))
|
||||||
|
return {'blocks': blocks}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue