feat: Telegram 알림 기능 추가 및 Slack 의존성 제거

- notification-hook.sh에서 Slack 웹훅 관련 코드 제거하고 Telegram 알림으로 변경
- lotto_auto_buy.py에서 Slack 알림 기능을 Telegram으로 대체
- 환경 변수 설정에 Telegram 관련 변수 추가
- 설정 파일에서 Slack 웹훅 URL 제거
This commit is contained in:
hyeonggil
2026-03-27 22:10:26 +09:00
parent 1b9e49c32c
commit cc8e37d6fe
8 changed files with 384 additions and 80 deletions

View File

@@ -35,12 +35,13 @@ from selenium.webdriver.common.keys import Keys
# 설정
# ─────────────────────────────────────────────
CONFIG = {
"USER_ID": os.environ.get("LOTTO_USER_ID", "hyeonggil2"),
"USER_PW": os.environ.get("LOTTO_USER_PW", "Rlaehdbs062$"),
"USER_ID": os.environ.get("LOTTO_USER_ID", ""),
"USER_PW": os.environ.get("LOTTO_USER_PW", ""),
"BUY_COUNT": 1, # 구매 게임 수 (1~10)
"HEADLESS": True, # True: 브라우저 창 숨김, False: 브라우저 창 표시
"LOG_FILE": "logs/lotto_log.json",
"SLACK_WEBHOOK_URL": os.environ.get("SLACK_WEBHOOK_URL", ""),
"TELEGRAM_BOT_TOKEN": os.environ.get("TELEGRAM_BOT_TOKEN", ""),
"TELEGRAM_CHAT_ID": os.environ.get("TELEGRAM_CHAT_ID", ""),
}
# 로깅 설정
@@ -263,10 +264,11 @@ def extract_purchase_result(driver):
return result
def send_slack(result):
"""Slack Webhook으로 구매 결과 알림 전송"""
url = CONFIG["SLACK_WEBHOOK_URL"]
if not url:
def send_telegram(result):
"""Telegram Bot으로 구매 결과 알림 전송"""
token = CONFIG["TELEGRAM_BOT_TOKEN"]
chat_id = CONFIG["TELEGRAM_CHAT_ID"]
if not token or not chat_id:
return
status = result.get("status", "unknown")
@@ -280,26 +282,30 @@ def send_slack(result):
for i, nums in enumerate(games, 1)
)
text = (
f":ticket: *로또 구매 완료!*\n"
f"🎟 *로또 구매 완료\!*\n"
f"회차: {round_no} 추첨일: {draw_date}\n"
f"{games_text}"
)
elif status == "failed":
text = f":warning: *로또 구매 실패*\n{result.get('error', '')}"
text = f"⚠️ *로또 구매 실패*\n{result.get('error', '')}"
else:
text = f":x: *로또 구매 오류*\n{result.get('error', status)}"
text = f" *로또 구매 오류*\n{result.get('error', status)}"
try:
payload = json.dumps({"text": text}).encode("utf-8")
payload = json.dumps({
"chat_id": int(chat_id),
"text": text,
"parse_mode": "MarkdownV2",
}).encode("utf-8")
req = urllib.request.Request(
url,
f"https://api.telegram.org/bot{token}/sendMessage",
data=payload,
headers={"Content-Type": "application/json"},
)
urllib.request.urlopen(req, timeout=10)
logger.info("Slack 알림 전송 완료")
logger.info("Telegram 알림 전송 완료")
except Exception as e:
logger.warning(f"Slack 알림 전송 실패: {e}")
logger.warning(f"Telegram 알림 전송 실패: {e}")
def save_log(result):
@@ -350,6 +356,11 @@ def main():
if balance >= 0 and balance < cost:
logger.error(f"예치금 부족! 현재: {balance:,}원, 필요: {cost:,}")
logger.error("동행복권 사이트에서 예치금을 충전해주세요.")
send_telegram({
"date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"status": "failed",
"error": f"예치금 부족! 현재: {balance:,}원, 필요: {cost:,}",
})
sys.exit(1)
# 3. 로또 구매
@@ -358,7 +369,7 @@ def main():
# 4. 결과 저장 및 Slack 알림
if result:
save_log(result)
send_slack(result)
send_telegram(result)
else:
failed = {
"date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
@@ -366,7 +377,7 @@ def main():
"error": "구매 결과를 확인할 수 없습니다.",
}
save_log(failed)
send_slack(failed)
send_telegram(failed)
logger.info("스크립트 실행 완료!")
@@ -378,7 +389,7 @@ def main():
"error": str(e),
}
save_log(error_result)
send_slack(error_result)
send_telegram(error_result)
finally:
if driver: