Spaces:
Running
Running
File size: 764 Bytes
9cf96c4 4800093 9cf96c4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
from datetime import datetime
from threading import Timer
import time
import requests
import os
# 每隔4分钟发送ping
def sendPingTask():
Timer(240, sendPing, ()).start()
def sendPing():
print("sendPing")
url = os.environ.get("WEBHOOK_URL")
headers = {
"Content-Type": "application/json"
}
payload = {
"content": "ping"
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200 or response.status_code == 204:
print("Message ping sent successfully")
sendPingTask()
else:
print(f"Failed to send message ping: {response.status_code}")
def run():
sendPingTask()
sendPing()
def pingpong():
print("Running pingpong")
run()
|