From 468676c432d23eaf48930270c286ef7eb45b5d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=94=EB=83=A5?= Date: Tue, 11 Feb 2025 23:53:09 +0900 Subject: [PATCH] =?UTF-8?q?Github=20Actions=EC=9D=98=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=EA=B3=BC=20=ED=95=99=EC=82=AC=EC=9D=BC=EC=A0=95=EC=9D=98=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20=EC=9D=B8=EC=8A=A4=ED=83=80=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/school-event.yml | 78 ++++++++++++++++ app/force-event.py | 33 +++++++ app/library/event/2025.json | 143 +++++++++++++++-------------- app/library/lib.py | 10 +- app/run.py | 15 ++- 5 files changed, 201 insertions(+), 78 deletions(-) create mode 100644 .github/workflows/school-event.yml create mode 100644 app/force-event.py diff --git a/.github/workflows/school-event.yml b/.github/workflows/school-event.yml new file mode 100644 index 0000000..cc6fc40 --- /dev/null +++ b/.github/workflows/school-event.yml @@ -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 diff --git a/app/force-event.py b/app/force-event.py new file mode 100644 index 0000000..2a5017d --- /dev/null +++ b/app/force-event.py @@ -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.") \ No newline at end of file diff --git a/app/library/event/2025.json b/app/library/event/2025.json index 4d70e20..25ef144 100644 --- a/app/library/event/2025.json +++ b/app/library/event/2025.json @@ -1,78 +1,81 @@ { - "02": { - "0": { - "start": 20250208, - "end": 20250302, - "data": "κ²¨μšΈλ°©ν•™ & λ΄„λ°©ν•™" + "last_update": "20250211", + "event": { + "02": { + "0": { + "start": 20250208, + "end": 20250302, + "data": "κ²¨μšΈλ°©ν•™ & λ΄„λ°©ν•™" + } }, - "1": { - "start": 20250303, - "end": 20250303, - "data": "μž…ν•™μ‹" - } - }, - "03": { - "0": { - "start": 20250301, - "end": 20250303, - "data": "μ‚ΌμΌμ ˆ" - } - }, - "04": { - "0": { - "start": 20250410, - "end": 20250410, - "data": "22λŒ€ κ΅­νšŒμ˜μ›μ„ κ±°" - } - }, - "05": { - "0": { - "start": 20250505, - "end": 20250505, - "data": "어린이날" + "03": { + "0": { + "start": 20250301, + "end": 20250303, + "data": "μ‚ΌμΌμ ˆ" + }, + "1": { + "start": 20250304, + "end": 20250304, + "data": "μž…ν•™μ‹" + } }, - "1": { - "start": 20250505, - "end": 20250506, - "data": "λΆ€μ²˜λ‹˜μ˜€μ‹ λ‚ " - } - }, - "06": { - "0": { - "start": 20250606, - "end": 20250606, - "data": "ν˜„μΆ©μΌ" - } - }, - "08": { - "0": { - "start": 20250815, - "end": 20250815, - "data": "κ΄‘λ³΅μ ˆ" - } - }, - "10": { - "0": { - "start": 20251003, - "end": 20251003, - "data": "개천절" + "04": { + "0": { + "start": 20250410, + "end": 20250410, + "data": "22λŒ€ κ΅­νšŒμ˜μ›μ„ κ±°" + } }, - "1": { - "start": 20251005, - "end": 20251008, - "data": "좔석" + "05": { + "0": { + "start": 20250505, + "end": 20250505, + "data": "어린이날" + }, + "1": { + "start": 20250505, + "end": 20250506, + "data": "λΆ€μ²˜λ‹˜μ˜€μ‹ λ‚ " + } }, - "2": { - "start": 20251009, - "end": 20251009, - "data": "ν•œκΈ€λ‚ " - } - }, - "12": { - "0": { - "start": 20251225, - "end": 20251225, - "data": "크리슀마슀" + "06": { + "0": { + "start": 20250606, + "end": 20250606, + "data": "ν˜„μΆ©μΌ" + } + }, + "08": { + "0": { + "start": 20250815, + "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": "크리슀마슀" + } } } } \ No newline at end of file diff --git a/app/library/lib.py b/app/library/lib.py index e0c4baa..d9e41fc 100644 --- a/app/library/lib.py +++ b/app/library/lib.py @@ -72,7 +72,8 @@ def 학사일정_μ–»κΈ°(): print("μ˜€λŠ˜μ€ 사싀", 였늘, "μ΄μ˜€λ‹€") with open(f"{ROOT}/library/event/{였늘.strftime("%Y")}.json") as 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") 사진 = Image.open(f"{ROOT}/library/skeleton_schoolevent.png") @@ -100,12 +101,15 @@ def 학사일정_μ–»κΈ°(): μ„ΈλΆ€μš”μ†Œ = ImageDraw.Draw(사진) μ„ΈλΆ€μš”μ†Œ.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') - 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 diff --git a/app/run.py b/app/run.py index 86011ee..7bdb96c 100644 --- a/app/run.py +++ b/app/run.py @@ -54,13 +54,18 @@ print("πŸ—¨οΈ | Uploaded at Discord") print(f"πŸ“† | Today Date : {MLSV_YMD}") # Check if today is the last day of the month -today = datetime.now() -first_day_of_next_month = today.replace(day=28) + timedelta(days=4) -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(): +였늘 = datetime.today() +내일 = 였늘 + timedelta(days=1) + +if 내일.month != 였늘.month: print("πŸ“… | Today is the last day of the month.") 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") else: print("πŸ“… | Today is not the last day of the month.")