This commit is contained in:
imnyang 2024-11-06 17:14:20 +09:00
commit bf706e58d8
14 changed files with 297 additions and 0 deletions

Binary file not shown.

17
app/library/init-auth.py Normal file
View file

@ -0,0 +1,17 @@
import library.vts as vts
vts.download(vts.get_board())
from instagrapi import Client
import json, os
import time
cl = Client()
cl.login(os.getenv("INSTAGRAM_ID"), os.getenv("INSTAGRAM_PASSWORD"))
json.dump(
cl.get_settings(),
open(f'{os.getenv("ROOT")}temp/cookies.json', 'w')
)
print("🍪 | Account information was successfully retrieved.")
print(f"📅 | Job ended at {time.time()}")

82
app/library/lib.py Normal file
View 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}.")

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

BIN
app/library/skeleton.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

57
app/library/vts.py Normal file
View file

@ -0,0 +1,57 @@
import requests, datetime
from bs4 import BeautifulSoup
import openpyxl, os
def get_board():
url = "http://isangjeong.icems.kr/boardCnts/list.do?searchType=S&page=1&boardID=33523&prntBoardID=0&prntBoardSeq=0&prntLev=0&m=0601&s=isangjeong"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
element = soup.select_one("html body div:nth-of-type(2) div:nth-of-type(3) div div:nth-of-type(2) section:nth-of-type(2) div:nth-of-type(2) div:nth-of-type(2) div:nth-of-type(2) div form table tbody tr:nth-of-type(1) td:nth-of-type(2) a")
onclick_value = element.get("onclick")
values = str(onclick_value[18:-1].replace("'", "")).replace(" ", "").split(",")
# for i in values:
# print(i)
return f"http://isangjeong.icems.kr/boardCnts/updateCnt.do?boardID={values[0]}&viewBoardID={values[1]}&boardSeq={values[2]}&lev={values[3]}"
path = f'{os.getenv("ROOT")}temp/downloaded_file.xlsx'
def download(url:str):
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
element = soup.select_one("html > body > div:nth-of-type(2) > div:nth-of-type(3) > div > div:nth-of-type(2) > section:nth-of-type(2) > div:nth-of-type(2) > div:nth-of-type(2) > div:nth-of-type(2) > div > form > table > tbody > tr:nth-of-type(2) > td > p > a:nth-of-type(1)")
herf_value = element.get("href")
response = requests.get("http://isangjeong.icems.kr"+herf_value)
with open(path, "wb") as file:
file.write(response.content)
def get_vts():
#download(get_board())
ws = openpyxl.load_workbook(path).active
vts_list = []
for row in ws.iter_rows(min_row=5, max_row=5, min_col=7, max_col=14):
for cell in row:
if cell.fill.start_color.index == 'FFFFFF00':
value = str(cell.value).split('(')[0].strip()\
.replace(" ", "")\
.replace("", "")\
.replace("", "")
vts_list.append(f"{datetime.datetime.today().year}{value}")
return vts_list
def get_vts_true_or_false():
vts_list = get_vts()
today = datetime.datetime.today().strftime("%Y%m%d")
if today in vts_list:
return True
else:
return False
return False