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 from datetime import datetime, timedelta 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((945, 110), f"{MLSV_YMD[:4]}년 {MLSV_YMD[4:6]}월 {MLSV_YMD[6:8]}일", font=세부_폰트, anchor="rs", fill=(255, 255, 255)) #세부요소.text((755, 80), f"2025년 01월 01일", font=세부_폰트, fill=(255, 255, 255)) 세부요소.text((945, 220), f"{급식_칼로리_얻기(MLSV_YMD)}", font=세부_폰트, anchor="rs", fill=(137, 202, 255)) if vts.VTS임(MLSV_YMD): 세부요소.text((830, 225), "with V.T.S.", font=세부_폰트, fill=(205, 173, 148)) 사진.save(f'{ROOT}/temp/{MLSV_YMD}.png') print("🍲 | Meal Info Image Saved") def 학사일정_얻기(): print("서코가고싶다발동") 오늘 = datetime.now() + timedelta(days=1) print("오늘은 사실", 오늘, "이였다") with open(f"{ROOT}/library/event/{오늘.strftime("%Y")}.json") as json_file: json_data = json.load(json_file) 마지막_업데이트 = json_data["last_update"] 학사일정 = json_data["event"][str(오늘.strftime("%m"))] # print(f"{ROOT}/library/skeleton.png") 사진 = Image.open(f"{ROOT}/library/skeleton_schoolevent.png") #if vts.get_vts_true_or_false() == True: 사진 = Image.open(f'{ROOT}/library/skeleton-vts.png') 학사일정_폰트 = ImageFont.truetype(font, 48) 세부_폰트 = ImageFont.truetype(font, 24) 제목요소 = ImageDraw.Draw(사진) for i, 일정 in enumerate(reversed(list(학사일정.values()))): if 일정['data']: start_date = datetime.strptime(str(일정['start']), "%Y%m%d") end_date = datetime.strptime(str(일정['end']), "%Y%m%d") if start_date == end_date: date_text = f"{start_date.day}일" elif start_date.year != end_date.year: date_text = f"{start_date.year}년 {start_date.month}월 {start_date.day}일 ~ {end_date.year}년 {end_date.month}월 {end_date.day}일" elif start_date.month != end_date.month: date_text = f"{start_date.month}월 {start_date.day}일 ~ {end_date.month}월 {end_date.day}일" else: date_text = f"{start_date.day}일 ~ {end_date.day}일" 제목요소.text((75, 930 - i * 60), f"{date_text} : {일정['data']}", font=학사일정_폰트, anchor="ls", fill=(255, 255, 255)) 세부요소 = ImageDraw.Draw(사진) 세부요소.text((810, 80), f"{오늘.strftime("%Y")}년 {오늘.strftime("%m")}월", font=세부_폰트, fill=(255, 255, 255)) def 포맷팅된_날짜(날짜:str): return f"{날짜[:4]}년 {날짜[4:6]}월 {날짜[6:8]}일" 세부요소.text((591, 200), f"마지막 업데이트 : {포맷팅된_날짜(마지막_업데이트)}", font=세부_폰트, fill=(137, 202, 255)) 사진.save(f'{ROOT}/temp/{오늘.strftime("%Y")}_{오늘.strftime("%m")}.png') print("🍲 | Meal Info Image Saved") return f'{ROOT}/temp/{오늘.strftime("%Y")}_{오늘.strftime("%m")}.png' def 스토리_얻기(MLSV_YMD:str): print("이건 왜?") # 1:1 to 9:16 temp/{MLSV_YMD}.png 사진 = None 사진 = 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" : "인천상정중학교" } ] if vts.VTS임(MLSV_YMD): data["content"] = f"{MLSV_YMD} | with V.T.S." 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}.")