모든 버그 해결
This commit is contained in:
parent
be4d6616f0
commit
e19aa64c8f
14 changed files with 96 additions and 31 deletions
35
.devcontainer/Dockerfile
Normal file
35
.devcontainer/Dockerfile
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
FROM python:3.12
|
||||
|
||||
RUN sed -i 's@deb.debian.org@ftp.kaist.ac.kr@g' /etc/apt/sources.list.d/debian.sources
|
||||
|
||||
# Setup Crontab
|
||||
|
||||
WORKDIR /code
|
||||
COPY crontab /code/crontab
|
||||
COPY requirements.txt /code/requirements.txt
|
||||
COPY .env /code/.env
|
||||
COPY app /code/app
|
||||
|
||||
RUN apt update && apt -y install tzdata && \
|
||||
ln -fs /usr/share/zoneinfo/Asia/Seoul /etc/localtime && \
|
||||
dpkg-reconfigure --frontend noninteractive tzdata && \
|
||||
apt update && apt -y install cron
|
||||
|
||||
COPY crontab /etc/cron.d/crontab
|
||||
RUN chmod 0644 /etc/cron.d/crontab
|
||||
RUN echo "" >> /etc/cron.d/crontab # Ensure newline at end of file
|
||||
RUN /usr/bin/crontab /etc/cron.d/crontab
|
||||
|
||||
# Setup Environment Variables
|
||||
|
||||
RUN export $(cat .env | xargs)
|
||||
|
||||
# Setup Python Environment
|
||||
WORKDIR /code
|
||||
RUN pip config set global.break-system-packages true
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
RUN rm -rf /etc/localtime
|
||||
RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
|
||||
|
||||
CMD ["cron", "-f"]
|
||||
6
.devcontainer/devcontainer.json
Normal file
6
.devcontainer/devcontainer.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
"context": ".."
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
ROOT="/root/today.isangjeong/"
|
||||
INSTAGRAM_ID="today.isangjeong"
|
||||
INSTAGRAM_PASSWORD="passwd"
|
||||
KEY="key"
|
||||
WEBHOOK_URL="webhook_url"
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -10,3 +10,6 @@ temp/
|
|||
|
||||
venv
|
||||
.venv
|
||||
|
||||
__pycache__/
|
||||
config.json
|
||||
|
|
@ -3,11 +3,13 @@
|
|||
오늘 급식도 인스타로
|
||||
|
||||
|
||||
실행하기 전에 `.env`가 필요합니다.
|
||||
실행하기 전에 `app/config.json`가 필요합니다.
|
||||
|
||||
`.env.example`을 참고해서 만들어주세요.
|
||||
`app/config.example.json`을 참고해서 만들어주세요.
|
||||
|
||||
|
||||
**이 프로젝트는 백업을 위한 레포로 친절하게 문서를 쓸 생각이 없습니다.**
|
||||
|
||||
`docker build --tag today-isangjeong:latest`
|
||||
`docker build --tag today-isangjeong:latest .`
|
||||
|
||||
`docker run -d -v /data/hdd/today.isanjeong-docker:/code/app/temp --name today-isangjeong today-isangjeong:latest`
|
||||
|
|
|
|||
7
app/config.example.json
Normal file
7
app/config.example.json
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"ROOT": "/code/app/",
|
||||
"INSTAGRAM_ID": "today.isangjeong",
|
||||
"INSTAGRAM_PASSWORD": "",
|
||||
"KEY": "",
|
||||
"WEBHOOK_URL": ""
|
||||
}
|
||||
|
|
@ -5,12 +5,18 @@ from instagrapi import Client
|
|||
import json, os
|
||||
import time
|
||||
|
||||
with open('../config.json') as json_file:
|
||||
json_data = json.load(json_file)
|
||||
|
||||
ROOT = json_data['ROOT']
|
||||
INSTAGRAM_AUTH = [json_data['INSTAGRAM_ID'], json_data['INSTAGRAM_PASSWORD']]
|
||||
|
||||
cl = Client()
|
||||
cl.login(os.getenv("INSTAGRAM_ID"), os.getenv("INSTAGRAM_PASSWORD"))
|
||||
cl.login(INSTAGRAM_AUTH[0], INSTAGRAM_AUTH[1])
|
||||
|
||||
json.dump(
|
||||
cl.get_settings(),
|
||||
open(f'{os.getenv("ROOT")}temp/cookies.json', 'w')
|
||||
open(f'{ROOT}temp/cookies.json', 'w')
|
||||
)
|
||||
|
||||
print("🍪 | Account information was successfully retrieved.")
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import re
|
||||
import json
|
||||
|
||||
def 영양정보_삭제(값:str):
|
||||
줄들 = 값.strip().split('\n')
|
||||
|
|
@ -15,13 +16,21 @@ from PIL import ImageFont
|
|||
import library.vts as vts
|
||||
import os
|
||||
|
||||
KEY = os.getenv("KEY")
|
||||
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("<br/>", "\n"))
|
||||
|
|
@ -32,25 +41,26 @@ def 급식_칼로리_얻기(MLSV_YMD:str):
|
|||
)
|
||||
return 답장.json()['mealServiceDietInfo'][1]['row'][0]['CAL_INFO']
|
||||
|
||||
font = f"{os.getenv("ROOT")}library/Pretendard-Bold.ttf"
|
||||
|
||||
def 얻기(MLSV_YMD:str):
|
||||
급식 = 급식_정보_얻기(MLSV_YMD)
|
||||
print(f"{ROOT}library/skeleton.png")
|
||||
사진 = Image.open(f"{ROOT}library/skeleton.png")
|
||||
|
||||
사진 = 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')
|
||||
#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(사진)
|
||||
제목요소.text((180, 750), 급식, font=급식_폰트, fill=(255, 255, 255))
|
||||
for i, line in enumerate(reversed(급식.split('\n'))):
|
||||
제목요소.text((75, 930 - i * 60), line, font=급식_폰트, anchor="ls", 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))
|
||||
세부요소.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'{os.getenv("ROOT")}temp/{MLSV_YMD}.png')
|
||||
사진.save(f'{ROOT}temp/{MLSV_YMD}.png')
|
||||
|
||||
print("🍲 | Meal Info Image Saved")
|
||||
|
||||
|
|
@ -71,7 +81,7 @@ def 디스코드(MLSV_YMD:str):
|
|||
]
|
||||
|
||||
print("🏓 | Sending Payload")
|
||||
result = requests.post(os.getenv('WEBHOOK_URL'), json = data)
|
||||
result = requests.post(WEBHOOK_URL, json = data)
|
||||
print("🏓 | Payload Sent")
|
||||
|
||||
try:
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 49 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 14 KiB |
|
|
@ -18,7 +18,7 @@ def get_board():
|
|||
|
||||
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'
|
||||
path = f'{os.getenv('ROOT')}temp/downloaded_file.xlsx'
|
||||
|
||||
def download(url:str):
|
||||
response = requests.get(url)
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ print("📅 | Date:", MLSV_YMD)
|
|||
|
||||
print("🍲 | Getting Meal Info Image")
|
||||
lib.얻기(MLSV_YMD)
|
||||
#lib.얻기(MLSV_YMD)
|
||||
|
||||
path = f"{os.getenv("ROOT")}temp/{MLSV_YMD}.png"
|
||||
path = f"{os.getenv('ROOT')}temp/{MLSV_YMD}.png"
|
||||
|
||||
print("📸 | Uploading Story")
|
||||
cl.photo_upload_to_story(
|
||||
|
|
|
|||
12
app/run.sh
12
app/run.sh
|
|
@ -1,22 +1,16 @@
|
|||
cd /root/isangjeong.today
|
||||
cd /code/isangjeong.today
|
||||
#rm -rf 20*.png
|
||||
|
||||
#rm -rf /etc/localtime
|
||||
#ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
|
||||
|
||||
# If doesn't have .venv folder, create it
|
||||
if [ ! -d "venv" ]; then
|
||||
python3 -m venv venv
|
||||
.venv/bin/pip install -r requirements.txt
|
||||
fi
|
||||
|
||||
# If doesn't have temp folder, create it
|
||||
if [ ! -d "temp" ]; then
|
||||
mkdir temp
|
||||
fi
|
||||
# If doesn't have temp/cookies.json, create it
|
||||
if [ ! -f "temp/cookies.json" ]; then
|
||||
.venv/bin/python3 library/init-auth.py
|
||||
python3 library/init-auth.py
|
||||
fi
|
||||
|
||||
.venv/bin/python3 run.py > temp/$(date +%Y%m%d-%H%M%S).log 2>&1
|
||||
python3 run.py > temp/$(date +%Y%m%d-%H%M%S).log 2>&1
|
||||
6
app/test.py
Normal file
6
app/test.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import library.lib as lib
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
MLSV_YMD = str((datetime.now() + timedelta(days=0)).strftime('%Y%m%d'))
|
||||
|
||||
lib.얻기("20241108")
|
||||
Loading…
Add table
Add a link
Reference in a new issue