From 3a888af95181533ea80c585fce0eca1088ccf452 Mon Sep 17 00:00:00 2001 From: imnyang Date: Thu, 9 Jan 2025 21:29:01 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=9F=20Github=20Action=EA=B3=BC=20?= =?UTF-8?q?=EC=8B=9C=EC=8A=A4=ED=85=9C=20=EC=98=AC=20=EA=B7=B8=EB=A6=B0!?= =?UTF-8?q?=20=EB=B0=9C=EC=A7=84=20=EC=A4=80=EB=B9=84=EC=99=84=EB=A3=8C!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/gen-config.sh | 31 +++++++++++++++++++++++++++++++ app/library/init-auth.py | 9 +++++++-- app/library/lib.py | 6 ++++-- app/run.py | 1 + app/run.sh | 13 ++++++++++--- 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 app/gen-config.sh diff --git a/app/gen-config.sh b/app/gen-config.sh new file mode 100644 index 0000000..6650f88 --- /dev/null +++ b/app/gen-config.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Required environment variables +required_vars=("BOT_ROOT" "BOT_INSTAGRAM_ID" "BOT_INSTAGRAM_PASSWORD" "BOT_KEY" "BOT_WEBHOOK_URL") + +# Check for missing environment variables +missing_vars=() +for var in "${required_vars[@]}"; do + if [ -z "${!var}" ]; then + missing_vars+=("$var") + fi +done + +if [ ${#missing_vars[@]} -ne 0 ]; then + echo "Error: Missing required environment variables:" + printf '%s\n' "${missing_vars[@]}" + exit 1 +fi + +# Generate config.json +cat > config.json << EOF +{ + "ROOT": "${BOT_ROOT}", + "INSTAGRAM_ID": "${BOT_INSTAGRAM_ID}", + "INSTAGRAM_PASSWORD": "${BOT_INSTAGRAM_PASSWORD}", + "KEY": "${BOT_KEY}", + "WEBHOOK_URL": "${BOT_WEBHOOK_URL}" +} +EOF + +echo "Successfully generated config.json" \ No newline at end of file diff --git a/app/library/init-auth.py b/app/library/init-auth.py index ddd6ba3..00e395e 100644 --- a/app/library/init-auth.py +++ b/app/library/init-auth.py @@ -9,10 +9,15 @@ 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']] + INSTAGRAM_AUTH = [json_data['INSTAGRAM_ID'], json_data['INSTAGRAM_PASSWORD'], json_data['INSTAGRAM_TOTP']] + cl = Client() -cl.login(INSTAGRAM_AUTH[0], INSTAGRAM_AUTH[1]) +code = cl.totp_generate_code(INSTAGRAM_AUTH[2]) +cl.login(INSTAGRAM_AUTH[0], INSTAGRAM_AUTH[1], verification_code=code) +cl.set_timzone_offset(9 * 60 * 60) +cl.set_user_agent('Instagram 361.0.0.46.88 Android (35/15; 394dpi; 1084x2412; Nothing; A065; Pong; qcom; ko_KR_#u-fw-sun-mu-celsius; 674675147)') +cl.get_settings() json.dump( cl.get_settings(), diff --git a/app/library/lib.py b/app/library/lib.py index a5be4c4..b801a52 100644 --- a/app/library/lib.py +++ b/app/library/lib.py @@ -43,8 +43,9 @@ def 급식_칼로리_얻기(MLSV_YMD:str): def 얻기(MLSV_YMD:str): + print("집가고싶다발동") 급식 = 급식_정보_얻기(MLSV_YMD) - print(f"{ROOT}library/skeleton.png") +# 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') @@ -65,6 +66,7 @@ def 얻기(MLSV_YMD:str): print("🍲 | Meal Info Image Saved") def 스토리_얻기(MLSV_YMD:str): + print("이건 왜?") # 1:1 to 9:16 temp/{MLSV_YMD}.png 사진 = Image.open(f"{ROOT}temp/{MLSV_YMD}.png") @@ -112,4 +114,4 @@ def 디스코드(MLSV_YMD:str): except requests.exceptions.HTTPError as err: print(err) else: - print(f"✨ | Payload successfully, code {result.status_code}.") \ No newline at end of file + print(f"✨ | Payload successfully, code {result.status_code}.") diff --git a/app/run.py b/app/run.py index 5162caf..a1c5e15 100644 --- a/app/run.py +++ b/app/run.py @@ -26,6 +26,7 @@ print("📅 | Getting MLSV_YMD Timestamp") print("📅 | Date:", MLSV_YMD) print("🍲 | Getting Meal Info Image") +lib.얻기(MLSV_YMD) lib.스토리_얻기(MLSV_YMD) print("📸 | Uploading Story") diff --git a/app/run.sh b/app/run.sh index a04fd45..1b144a8 100644 --- a/app/run.sh +++ b/app/run.sh @@ -1,3 +1,10 @@ +export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin +echo "Debug: Script started at $(date)" >> /code/app/temp/debug.log +echo "Debug: Current directory is $(pwd)" >> /code/app/temp/debug.log +echo "Debug: User is $(whoami)" >> /code/app/temp/debug.log +echo "Debug: Environment variables:" >> /code/app/temp/debug.log +env >> /code/app/temp/debug.log + cd /code/app # If doesn't have temp folder, create it @@ -7,7 +14,7 @@ fi # If doesn't have temp/cookies.json, create it if [ ! -f "temp/cookies.json" ]; then - python3 library/init-auth.py + /code/app/venv/bin/python3 library/init-auth.py fi # Set the log file name with the current date and time @@ -15,7 +22,7 @@ log_file="temp/$(date +%Y%m%d-%H%M%S).log" # Run the Python script with or without --today and output to both the console and log file if [[ "$1" == "--today" ]]; then - python3 run.py --today | tee "$log_file" + /code/app/venv/bin/python3 run.py --today | tee "$log_file" else - python3 run.py | tee "$log_file" + /code/app/venv/bin/python3 run.py | tee "$log_file" fi