Skip to content

Instantly share code, notes, and snippets.

@HorseCheng
Created April 3, 2024 17:55
Show Gist options
  • Save HorseCheng/6668a53a8575f4e628f74c36ffb42ec9 to your computer and use it in GitHub Desktop.
Save HorseCheng/6668a53a8575f4e628f74c36ffb42ec9 to your computer and use it in GitHub Desktop.
地牛Wake up 通知腳本
python earthquake.py %1 %2
import sys
import traceback
import requests
try:
chat_id = "888888888" # Telegram 頻道 id
token = 'bot8888888888:AAAAAAAAA_aaaa-aaaaaaaaaaaaaaaaaaaa' # Telegram bot token
line_token = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' # Line 通知 token
magnitude = str(sys.argv[1]).replace("+","強").replace("-","弱")
second = int(sys.argv[2])
text= f"注意! XX區{second}秒後將發生{magnitude}級地震!!"
# Telegram 通知
requests.post(f"https://api.telegram.org/{token}/sendMessage?chat_id={chat_id}&text={text}")
# Line 通知
headers = {
"Authorization": "Bearer " + line_token,
"Content-Type" : "application/x-www-form-urlencoded"
}
payload = {'message': text }
requests.post("https://notify-api.line.me/api/notify", headers = headers, params = payload)
except Exception as e:
with open("record_earth.txt","a", encoding='utf-8') as a:
a.write(str(traceback.format_exc()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment