自己填写这些数据:
还有这些:
以及需要查询的网址,
我这里写的是复旦大学
如果复旦大学出成绩或者泄露成绩了,就会一秒发短信通知我哈哈哈
import requests
import schedule
import time
import json
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.sms.v20210111 import sms_client, models
# Twilio API 配置
TWILIO_ACCOUNT_SID = ' ???' # 这里填写自己的账号sid
TWILIO_AUTH_TOKEN = '????' # 这里填写自己的账号tokenID
TO_PHONE_NUMBER = '+86???' # 这里填写自己的手机号
def send_sms(message):
try:
cred = credential.Credential(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
# 实例化一个http选项,可选的,没有特殊需求可以跳过
httpProfile = HttpProfile()
httpProfile.endpoint = "sms.tencentcloudapi.com"
# 实例化要请求产品的client对象,clientProfile是可选的
client = sms_client.SmsClient(cred, "ap-nanjing")
# 实例化一个请求对象,每个接口都会对应一个request对象
req = models.SendSmsRequest()
params = {
"PhoneNumberSet" :[TO_PHONE_NUMBER],
"SmsSdkAppId":"1400961233", # 这个需要去腾讯云申请自己的sDKAPPid
"TemplateId":"2351995", # 这个需要去腾讯云申请TemplateId
"SignName":"评舍公众号" # 这个需要用到签名
}
req.from_json_string(json.dumps(params))
# 返回的resp是一个SendSmsResponse的实例,与请求对象对应
resp = client.SendSms(req)
# 输出json格式的字符串回包
print(f"短信发送成功,SID: {resp.to_json_string()}")
except TencentCloudSDKException as err:
print(f"发送短信出错: {err}")
def fetch_webpage():
try:
response = requests.get('https://gsas.fudan.edu.cn/sscjcx/index')
response.raise_for_status() # 检查请求是否成功
print(f"成功获取网页,状态码: {response.status_code}")
# 在这里可以处理网页内容,比如打印或保存
print(response.text[:]) # 打印前 100 个字符
if "查询时间暂未开放" not in response.text : # 如果是暂未开放状态
print("error")
send_sms("opened!!opened!!")
except requests.RequestException as e:
print(f"请求出错: {e}")
# 每 5分钟执行一次
schedule.every(5).minutes.do(fetch_webpage)
# 运行调度器
if __name__ == "__main__":
fetch_webpage()
print("开始每 5分钟查询一次网页...")
for _ in range(99999999): # 死循环
schedule.run_pending()
time.sleep(60) # 每分钟检查一次调度任务