import re import json 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 with open('./config.json') as json_file: json_data = json.load(json_file) KEY = json_data['KEY'] ROOT = json_data['ROOT'] font = f"{ROOT}library/Pretendard-Bold.ttf" WEBHOOK_URL = json_data['WEBHOOK_URL'] # 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}" ) print(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}") print(답장.json()) DDISH_NM = 답장.json()['mealServiceDietInfo'][1]['row'][0]['DDISH_NM'] return 영양정보_삭제(DDISH_NM.replace("
", "\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'] def 얻기(MLSV_YMD:str): print("집가고싶다발동") 급식 = 급식_정보_얻기(MLSV_YMD) # print(f"{ROOT}library/skeleton.png") 사진 = Image.open(f"{ROOT}library/skeleton.png") #if vts.get_vts_true_or_false() == True: 사진 = Image.open(f'{ROOT}library/skeleton-vts.png') 급식_폰트 = ImageFont.truetype(font, 56) 세부_폰트 = ImageFont.truetype(font, 24) 제목요소 = ImageDraw.Draw(사진) for i, line in enumerate(reversed(급식.split('\n'))): 제목요소.text((75, 930 - i * 60), line, font=급식_폰트, anchor="ls", fill=(255, 255, 255)) 세부요소 = ImageDraw.Draw(사진) 세부요소.text((767, 80), f"{MLSV_YMD[:4]}년 {MLSV_YMD[4:6]}월 {MLSV_YMD[6:8]}일", font=세부_폰트, fill=(255, 255, 255)) 세부요소.text((825, 200), f"{급식_칼로리_얻기(MLSV_YMD)}", font=세부_폰트, fill=(137, 202, 255)) 사진.save(f'{ROOT}temp/{MLSV_YMD}.png') print("🍲 | Meal Info Image Saved") def 스토리_얻기(MLSV_YMD:str): print("이건 왜?") # 1:1 to 9:16 temp/{MLSV_YMD}.png 사진 = Image.open(f"{ROOT}temp/{MLSV_YMD}.png") 가로, 세로 = 사진.size 비율 = 9 / 16 가로_비율 = 가로 / 세로 if 가로_비율 < 비율: 새_가로 = int(세로 * 비율) 새_세로 = 세로 새_사진 = Image.new("RGB", (새_가로, 새_세로), (10, 10, 10)) 사진 = 사진.resize((int(가로 * 0.85), int(세로 * 0.85)), Image.LANCZOS) 새_사진.paste(사진, (int((새_가로 - 사진.width) / 2), int((새_세로 - 사진.height) / 2))) else: 새_가로 = 가로 새_세로 = int(가로 / 비율) 새_사진 = Image.new("RGB", (새_가로, 새_세로), (10, 10, 10)) 사진 = 사진.resize((int(가로 * 0.85), int(세로 * 0.85)), Image.LANCZOS) 새_사진.paste(사진, (int((새_가로 - 사진.width) / 2), int((새_세로 - 사진.height) / 2))) 새_사진.save(f'temp/{MLSV_YMD}-story.png') print("🍲 | Story 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(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}.")