Github Actions의 설정과 학사일정의 대한 정보 추가 및 인스타 업로드 연동

This commit is contained in:
암냥 2025-02-11 23:53:09 +09:00
commit 468676c432
5 changed files with 201 additions and 78 deletions

78
.github/workflows/school-event.yml vendored Normal file
View file

@ -0,0 +1,78 @@
name: School Event Manual
on:
workflow_dispatch:
jobs:
run:
runs-on: ubuntu-latest
environment: Main
env:
BOT_ROOT: ${{ vars.BOT_ROOT }}
BOT_INSTAGRAM_ID: ${{ secrets.BOT_INSTAGRAM_ID }}
BOT_INSTAGRAM_PASSWD: ${{ secrets.BOT_INSTAGRAM_PASSWD }}
BOT_INSTAGRAM_TOTP: ${{ secrets.BOT_INSTAGRAM_TOTP }}
BOT_KEY: ${{ secrets.BOT_KEY }}
BOT_WEBHOOK_URL: ${{ secrets.BOT_WEBHOOK_URL }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.12"
# Cache Python dependencies
- name: Cache Python dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
# Cache cookie.json
- name: Cache cookie.json with timestamp check
uses: actions/cache@v3
with:
path: /home/runner/work/today.isangjeong/today.isangjeong/app/temp/auth/cookies.json
key: ${{ runner.os }}-cookie-${{ steps.timestamp.outputs.timestamp }}
restore-keys: |
${{ runner.os }}-cookie-
- name: Set timestamp for cookie.json
id: timestamp
run: |
echo "::set-output name=timestamp::$(date -r /home/runner/work/today.isangjeong/today.isangjeong/app/temp/auth/cookies.json +'%s')"
- name: Install dependencies (only if requirements.txt changed)
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt || echo "No changes in requirements.txt, skipping installation"
- name: Set Permissions
run: |
chmod +x app/run.sh app/gen-config.sh
- name: Generate Config
run: |
cd app
./gen-config.sh
- name: Add SSH private key
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
- name: Start SOCKS proxy with SSH
run: |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_ed25519 -D 9999 -f -N imnyang@imnya.ng -p5322
echo "SOCKS proxy started"
- name: Run application
run: |
cd app
python3 force-event.py

33
app/force-event.py Normal file
View file

@ -0,0 +1,33 @@
import json
from instagrapi import Client
from datetime import datetime, timedelta
import library.lib as lib
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']
print("🍪 | Retrieving saved account information.")
cl = Client(json.load(open('./temp/auth/cookies.json')))
cl.set_proxy("socks5h://localhost:9999")
print("🍪 | Account information was successfully retrieved.")
오늘 = datetime.today()
내일 = 오늘 + timedelta(days=1)
MLSV_YMD = (datetime.now() + timedelta(days=1)).strftime('%Y%m%d')
print("📅 | Today is the last day of the month.")
print("📆 | Uploading School Event Post")
학사일정_경로 = lib.학사일정_얻기(MLSV_YMD)
cl.photo_upload(
학사일정_경로,
caption=f"#인천상정중학교 #상정중학교 #학사일정 \n{내일.strftime("%Y")}{내일.strftime("%m")}월 학사일정",
extra_data={'is_paid_partnership': False}
)
print("📆 | School Event Post Uploaded")
print("🎉 | All tasks completed.")

View file

@ -1,78 +1,81 @@
{ {
"02": { "last_update": "20250211",
"0": { "event": {
"start": 20250208, "02": {
"end": 20250302, "0": {
"data": "겨울방학 & 봄방학" "start": 20250208,
"end": 20250302,
"data": "겨울방학 & 봄방학"
}
}, },
"1": { "03": {
"start": 20250303, "0": {
"end": 20250303, "start": 20250301,
"data": "입학식" "end": 20250303,
} "data": "삼일절"
}, },
"03": { "1": {
"0": { "start": 20250304,
"start": 20250301, "end": 20250304,
"end": 20250303, "data": "입학식"
"data": "삼일절" }
}
},
"04": {
"0": {
"start": 20250410,
"end": 20250410,
"data": "22대 국회의원선거"
}
},
"05": {
"0": {
"start": 20250505,
"end": 20250505,
"data": "어린이날"
}, },
"1": { "04": {
"start": 20250505, "0": {
"end": 20250506, "start": 20250410,
"data": "부처님오신날" "end": 20250410,
} "data": "22대 국회의원선거"
}, }
"06": {
"0": {
"start": 20250606,
"end": 20250606,
"data": "현충일"
}
},
"08": {
"0": {
"start": 20250815,
"end": 20250815,
"data": "광복절"
}
},
"10": {
"0": {
"start": 20251003,
"end": 20251003,
"data": "개천절"
}, },
"1": { "05": {
"start": 20251005, "0": {
"end": 20251008, "start": 20250505,
"data": "추석" "end": 20250505,
"data": "어린이날"
},
"1": {
"start": 20250505,
"end": 20250506,
"data": "부처님오신날"
}
}, },
"2": { "06": {
"start": 20251009, "0": {
"end": 20251009, "start": 20250606,
"data": "한글날" "end": 20250606,
} "data": "현충일"
}, }
"12": { },
"0": { "08": {
"start": 20251225, "0": {
"end": 20251225, "start": 20250815,
"data": "크리스마스" "end": 20250815,
"data": "광복절"
}
},
"10": {
"0": {
"start": 20251003,
"end": 20251003,
"data": "개천절"
},
"1": {
"start": 20251005,
"end": 20251008,
"data": "추석"
},
"2": {
"start": 20251009,
"end": 20251009,
"data": "한글날"
}
},
"12": {
"0": {
"start": 20251225,
"end": 20251225,
"data": "크리스마스"
}
} }
} }
} }

View file

@ -72,7 +72,8 @@ def 학사일정_얻기():
print("오늘은 사실", 오늘, "이였다") print("오늘은 사실", 오늘, "이였다")
with open(f"{ROOT}/library/event/{오늘.strftime("%Y")}.json") as json_file: with open(f"{ROOT}/library/event/{오늘.strftime("%Y")}.json") as json_file:
json_data = json.load(json_file) json_data = json.load(json_file)
학사일정 = json_data[str(오늘.strftime("%m"))] 마지막_업데이트 = json_data["last_update"]
학사일정 = json_data["event"][str(오늘.strftime("%m"))]
# print(f"{ROOT}/library/skeleton.png") # print(f"{ROOT}/library/skeleton.png")
사진 = Image.open(f"{ROOT}/library/skeleton_schoolevent.png") 사진 = Image.open(f"{ROOT}/library/skeleton_schoolevent.png")
@ -100,12 +101,15 @@ def 학사일정_얻기():
세부요소 = ImageDraw.Draw(사진) 세부요소 = ImageDraw.Draw(사진)
세부요소.text((810, 80), f"{오늘.strftime("%Y")}{오늘.strftime("%m")}", font=세부_폰트, fill=(255, 255, 255)) 세부요소.text((810, 80), f"{오늘.strftime("%Y")}{오늘.strftime("%m")}", font=세부_폰트, fill=(255, 255, 255))
#세부요소.text((825, 200), f"{급식_칼로리_얻기(MLSV_YMD)}", font=세부_폰트, fill=(137, 202, 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') 사진.save(f'{ROOT}/temp/{오늘.strftime("%Y")}_{오늘.strftime("%m")}.png')
print("🍲 | Meal Info Image Saved") print("🍲 | Meal Info Image Saved")
return f'{ROOT}/temp/{오늘.strftime("%Y")}_{오늘.strftime("%m")}.png'
def 스토리_얻기(MLSV_YMD:str): def 스토리_얻기(MLSV_YMD:str):
print("이건 왜?") print("이건 왜?")
# 1:1 to 9:16 temp/{MLSV_YMD}.png # 1:1 to 9:16 temp/{MLSV_YMD}.png

View file

@ -54,13 +54,18 @@ print("🗨️ | Uploaded at Discord")
print(f"📆 | Today Date : {MLSV_YMD}") print(f"📆 | Today Date : {MLSV_YMD}")
# Check if today is the last day of the month # Check if today is the last day of the month
today = datetime.now() 오늘 = datetime.today()
first_day_of_next_month = today.replace(day=28) + timedelta(days=4) 내일 = 오늘 + timedelta(days=1)
last_day_of_this_month = first_day_of_next_month - timedelta(days=first_day_of_next_month.day)
if today.date() == last_day_of_this_month.date(): if 내일.month != 오늘.month:
print("📅 | Today is the last day of the month.") print("📅 | Today is the last day of the month.")
print("📆 | Uploading School Event Post") print("📆 | Uploading School Event Post")
lib.학사일정_얻기(MLSV_YMD) 학사일정_경로 = lib.학사일정_얻기(MLSV_YMD)
cl.photo_upload(
학사일정_경로,
caption=f"#인천상정중학교 #상정중학교 #학사일정 \n{내일.strftime("%Y")}{내일.strftime("%m")}월 학사일정",
extra_data={'is_paid_partnership': False}
)
print("📆 | School Event Post Uploaded") print("📆 | School Event Post Uploaded")
else: else:
print("📅 | Today is not the last day of the month.") print("📅 | Today is not the last day of the month.")