2024-03-30 09:48:25 +00:00
|
|
|
|
import requests
|
|
|
|
|
import re
|
|
|
|
|
import time
|
|
|
|
|
import os
|
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
import json
|
|
|
|
|
import schedule
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
# 读取外部 JSON 文件中的数据
|
|
|
|
|
with open('data.json', 'r') as file:
|
|
|
|
|
json_data = json.load(file)
|
|
|
|
|
# 普通用户
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("----------提醒----------")
|
|
|
|
|
print("项目地址:https://github.com/JasonYANG170/AutoCheckBJMF")
|
|
|
|
|
print("请查看教程以获取Cookie和班级ID")
|
|
|
|
|
print("提示:你可以在json文件中输入配置信息,程序将会直接导入")
|
|
|
|
|
print("----------配置信息(必填)----------")
|
|
|
|
|
if (json_data['class'] == "123"):
|
|
|
|
|
print("请通过查看教程抓包获取班级ID")
|
|
|
|
|
ClassID = input("请输入班级ID:")
|
|
|
|
|
else:
|
|
|
|
|
ClassID = json_data['class']
|
|
|
|
|
print("输入的经纬度格式为x.x.x")
|
|
|
|
|
if (json_data['lat'] == "123"):
|
|
|
|
|
X = input("请输入纬度:")
|
|
|
|
|
else:
|
|
|
|
|
X = json_data['lat']
|
|
|
|
|
if (json_data['lng'] == "123"):
|
|
|
|
|
Y = input("请输入经度:")
|
|
|
|
|
else:
|
|
|
|
|
Y = json_data['lng']
|
|
|
|
|
if (json_data['acc'] == "123"):
|
|
|
|
|
ACC = input("请输入海拔:")
|
|
|
|
|
else:
|
|
|
|
|
ACC = json_data['acc'] # input("请输入海拔:")
|
|
|
|
|
if (json_data['time'] == 123):
|
|
|
|
|
SearchTime = int(input("请输入检索间隔,建议>=60s:"))
|
|
|
|
|
else:
|
|
|
|
|
SearchTime = json_data['time'] # int(input("请输入检索时长,建议>60s:"))
|
|
|
|
|
print("----------配置Cookie----------")
|
|
|
|
|
print("请通过查看教程抓包获取Cookie")
|
|
|
|
|
print("使用电脑抓取的Cookie会在电脑微信关闭时失效,失效后请重新抓取")
|
|
|
|
|
if (json_data['cookie'] == "123"):
|
|
|
|
|
MyCookie = input("请输入你的Cookie:")
|
|
|
|
|
else:
|
|
|
|
|
scheduletime = json_data['cookie'] # int(input("请输入检索时长,建议>60s:"))
|
|
|
|
|
print("----------配置定时任务(可选)----------")
|
|
|
|
|
print("格式为00:00,不设置定时请留空")
|
|
|
|
|
print("提示:请使用英文符号“:”不要使用中文符号“:”")
|
|
|
|
|
if (json_data['scheduletime'] == ""):
|
|
|
|
|
scheduletime = input("请输入开启时间:")
|
|
|
|
|
else:
|
|
|
|
|
scheduletime = json_data['scheduletime'] # int(input("请输入检索时长,建议>60s:"))
|
|
|
|
|
print("----------配置通知(可选)----------")
|
|
|
|
|
if (json_data['pushplus'] == "123"):
|
|
|
|
|
token = input("请输入pushplus密钥,不需要请留空:")
|
|
|
|
|
else:
|
|
|
|
|
token = json_data['pushplus'] # input("请输入pushplus密钥:")
|
|
|
|
|
print("----------信息----------")
|
|
|
|
|
print("班级ID:"+ClassID)
|
|
|
|
|
print("经度:" + Y)
|
|
|
|
|
print("纬度:" + X)
|
|
|
|
|
print("海拔:" + ACC)
|
|
|
|
|
print("检索间隔:" + str(SearchTime))
|
|
|
|
|
print("Cookie值:" + MyCookie)
|
|
|
|
|
print("定时:" + scheduletime)
|
|
|
|
|
print("通知token:" + token)
|
|
|
|
|
print("---------------------")
|
|
|
|
|
# 输出用户输入的内容
|
|
|
|
|
print("程序已执行")
|
|
|
|
|
|
|
|
|
|
# GitHub Actions自动任务
|
|
|
|
|
# ClassID = os.environ['ClassID']
|
|
|
|
|
# X = os.environ['X']
|
|
|
|
|
# Y = os.environ['Y']
|
|
|
|
|
# ACC = os.environ['ACC']
|
|
|
|
|
# SearchTime = os.environ['SearchTime']
|
|
|
|
|
# MyCookie = os.environ['MyCookie']
|
|
|
|
|
# token = os.environ['token']
|
|
|
|
|
#scheduletime = os.environ['scheduletime']
|
|
|
|
|
|
|
|
|
|
# 本地面板运行
|
|
|
|
|
#ClassID = ''
|
|
|
|
|
#X = ''
|
|
|
|
|
#Y = ''
|
|
|
|
|
#ACC = ''
|
|
|
|
|
#SearchTime = 60
|
|
|
|
|
#MyCookie = ''
|
|
|
|
|
#token = '' #在pushplus网站中可以找到
|
|
|
|
|
#scheduletime =''
|
|
|
|
|
def job():
|
|
|
|
|
current_time = datetime.now()
|
|
|
|
|
print("进入检索,当前时间为:", current_time)
|
|
|
|
|
title = '班级魔法自动签到任务' # 改成你要的标题内容
|
|
|
|
|
url = 'http://k8n.cn/student/course/' + ClassID + '/punchs'
|
|
|
|
|
|
|
|
|
|
headers = {
|
|
|
|
|
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; AKT-AK47 Build/USER-AK47; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/116.0.0.0 Mobile Safari/537.36 XWEB/1160065 MMWEBSDK/20231202 MMWEBID/1136 MicroMessenger/8.0.47.2560(0x28002F35) WeChat/arm64 Weixin NetType/4G Language/zh_CN ABI/arm64',
|
|
|
|
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/wxpic,image/tpg,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
|
|
|
'X-Requested-With': 'com.tencent.mm',
|
|
|
|
|
'Referer': 'http://k8n.cn/student/course/'+ClassID,
|
|
|
|
|
'Accept-Encoding': 'gzip, deflate',
|
|
|
|
|
'Accept-Language': 'zh-CN,zh-SG;q=0.9,zh;q=0.8,en-SG;q=0.7,en-US;q=0.6,en;q=0.5',
|
|
|
|
|
'Cookie': MyCookie
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
response = requests.get(url, headers=headers)
|
|
|
|
|
print("响应:", response)
|
|
|
|
|
|
|
|
|
|
# 创建 Beautiful Soup 对象解析 HTML
|
|
|
|
|
soup = BeautifulSoup(response.text, 'html.parser')
|
|
|
|
|
|
|
|
|
|
# 使用正则表达式从 HTML 文本中提取所有 punch_gps() 中的数字
|
|
|
|
|
pattern = re.compile(r'punch_gps\((\d+)\)')
|
|
|
|
|
matches = pattern.findall(response.text)
|
|
|
|
|
print("找到GPS定位签到:", matches)
|
|
|
|
|
pattern2 = re.compile(r'punchcard_(\d+)')
|
|
|
|
|
matches2 = pattern2.findall(response.text)
|
|
|
|
|
print("找到扫码签到:", matches2)
|
|
|
|
|
matches.extend(matches2)
|
|
|
|
|
if matches:
|
|
|
|
|
for match in matches:
|
|
|
|
|
print(match)
|
|
|
|
|
url = "http://k8n.cn/student/punchs/course/" + ClassID + "/" + match
|
|
|
|
|
payload = {
|
|
|
|
|
'id': match,
|
|
|
|
|
'lat': X,
|
|
|
|
|
'lng': Y,
|
|
|
|
|
'acc': ACC,#未知,可能是高度
|
|
|
|
|
'res': '',#未知,抓取时该函数为空,可能是密码签到
|
|
|
|
|
'gps_addr': ''#未知,抓取时该函数为空
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = requests.post(url, headers=headers, data=payload)
|
|
|
|
|
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
|
print("请求成功")
|
|
|
|
|
print("响应:", response)
|
|
|
|
|
|
|
|
|
|
# 解析响应的 HTML 内容
|
|
|
|
|
soup_response = BeautifulSoup(response.text, 'html.parser')
|
|
|
|
|
h1_tag = soup_response.find('h1')
|
|
|
|
|
|
|
|
|
|
if h1_tag:
|
|
|
|
|
h1_text = h1_tag.text
|
|
|
|
|
print(h1_text)
|
|
|
|
|
# encoding:utf-8
|
|
|
|
|
if(token!=""):
|
|
|
|
|
url = 'http://www.pushplus.plus/send?token=' + token + '&title=' + title + '&content=' + h1_text # 不使用请注释
|
|
|
|
|
requests.get(url) # 不使用请注释
|
|
|
|
|
continue # 返回到查找进行中的签到循环
|
|
|
|
|
else:
|
|
|
|
|
print("未找到 <h1> 标签,可能存在错误")
|
|
|
|
|
else:
|
|
|
|
|
print("请求失败,状态码:", response.status_code)
|
|
|
|
|
else:
|
|
|
|
|
print("未找到在进行的签到")
|
|
|
|
|
|
|
|
|
|
# 可以设置一个间隔时间,避免过于频繁地请求
|
|
|
|
|
time.sleep(SearchTime) # 暂停10秒后重新尝试
|
|
|
|
|
|
|
|
|
|
if(scheduletime!=""):
|
|
|
|
|
print("等待设定时间"+scheduletime+"到达")
|
|
|
|
|
# 设置定时任务,在每天的早上8点触发
|
|
|
|
|
schedule.every().day.at(scheduletime).do(job)
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
|
|
schedule.run_pending()
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
job()
|