slack 메시지 변환하는 부분 작성중
This commit is contained in:
parent
660f85f145
commit
91e986b475
3 changed files with 37 additions and 8 deletions
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]:
|
||||
return {
|
||||
|
|
@ -8,3 +9,35 @@ def markdown(text: str) -> Dict[str, Any]:
|
|||
'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