Init
This commit is contained in:
commit
bf706e58d8
14 changed files with 297 additions and 0 deletions
82
app/library/lib.py
Normal file
82
app/library/lib.py
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
import re
|
||||
|
||||
def 영양정보_삭제(값:str):
|
||||
줄들 = 값.strip().split('\n')
|
||||
청소된_줄 = [re.sub(r'\(.*?\)', '', 줄).strip() for 줄 in 줄들]
|
||||
결과 = '\n'.join(청소된_줄)
|
||||
|
||||
return 결과
|
||||
|
||||
import requests
|
||||
from PIL import Image
|
||||
from PIL import ImageDraw
|
||||
from PIL import ImageFont
|
||||
|
||||
import library.vts as vts
|
||||
import os
|
||||
|
||||
KEY = os.getenv("KEY")
|
||||
|
||||
# DDISH_NM
|
||||
def 급식_정보_얻기(MLSV_YMD:str):
|
||||
답장 = requests.get(
|
||||
f"https://open.neis.go.kr/hub/mealServiceDietInfo?Type=json&ATPT_OFCDC_SC_CODE=E10&SD_SCHUL_CODE=7331071&MLSV_YMD={MLSV_YMD}&KEY={KEY}"
|
||||
)
|
||||
DDISH_NM = 답장.json()['mealServiceDietInfo'][1]['row'][0]['DDISH_NM']
|
||||
|
||||
return 영양정보_삭제(DDISH_NM.replace("<br/>", "\n"))
|
||||
|
||||
def 급식_칼로리_얻기(MLSV_YMD:str):
|
||||
답장 = requests.get(
|
||||
f"https://open.neis.go.kr/hub/mealServiceDietInfo?Type=json&ATPT_OFCDC_SC_CODE=E10&SD_SCHUL_CODE=7331071&MLSV_YMD={MLSV_YMD}&KEY={KEY}"
|
||||
)
|
||||
return 답장.json()['mealServiceDietInfo'][1]['row'][0]['CAL_INFO']
|
||||
|
||||
font = f"{os.getenv("ROOT")}library/Pretendard-Bold.ttf"
|
||||
|
||||
def 얻기(MLSV_YMD:str):
|
||||
급식 = 급식_정보_얻기(MLSV_YMD)
|
||||
|
||||
사진 = Image.open(f'{os.getenv("ROOT")}library/skeleton.png')
|
||||
if vts.get_vts_true_or_false() == True: 사진 = Image.open(f'{os.getenv("ROOT")}library/skeleton-vts.png')
|
||||
|
||||
급식_폰트 = ImageFont.truetype(font, 56)
|
||||
세부_폰트 = ImageFont.truetype(font, 24)
|
||||
|
||||
제목요소 = ImageDraw.Draw(사진)
|
||||
제목요소.text((180, 750), 급식, font=급식_폰트, fill=(255, 255, 255))
|
||||
|
||||
세부요소 = ImageDraw.Draw(사진)
|
||||
세부요소.text((560, 623), f"{MLSV_YMD[:4]}.{MLSV_YMD[4:6]}.{MLSV_YMD[6:8]}", font=세부_폰트, fill=(255, 255, 255))
|
||||
세부요소.text((540, 650), f"{급식_칼로리_얻기(MLSV_YMD)}", font=세부_폰트, fill=(137, 202, 255))
|
||||
|
||||
사진.save(f'{os.getenv("ROOT")}temp/{MLSV_YMD}.png')
|
||||
|
||||
print("🍲 | Meal Info Image Saved")
|
||||
|
||||
def 디스코드(MLSV_YMD:str):
|
||||
|
||||
오늘급식 = 급식_정보_얻기(MLSV_YMD)
|
||||
|
||||
data = {
|
||||
"content" : MLSV_YMD,
|
||||
"username" : "@today.isangjeong"
|
||||
}
|
||||
|
||||
data["embeds"] = [
|
||||
{
|
||||
"description" : 오늘급식,
|
||||
"title" : "인천상정중학교"
|
||||
}
|
||||
]
|
||||
|
||||
print("🏓 | Sending Payload")
|
||||
result = requests.post(os.getenv('WEBHOOK_URL'), json = data)
|
||||
print("🏓 | Payload Sent")
|
||||
|
||||
try:
|
||||
result.raise_for_status()
|
||||
except requests.exceptions.HTTPError as err:
|
||||
print(err)
|
||||
else:
|
||||
print(f"✨ | Payload successfully, code {result.status_code}.")
|
||||
Loading…
Add table
Add a link
Reference in a new issue