mirror of
https://github.com/HChaZZY/NodeSeek-Signin.git
synced 2025-12-06 11:33:49 +08:00
只计算本月收益统计
This commit is contained in:
@@ -244,7 +244,7 @@ def sign(ns_cookie, ns_random):
|
||||
|
||||
# ---------------- 查询签到收益统计函数 ----------------
|
||||
def get_signin_stats(ns_cookie, days=30):
|
||||
"""查询指定天数内的签到收益统计"""
|
||||
"""查询本月的签到收益统计"""
|
||||
if not ns_cookie:
|
||||
return None, "无有效Cookie"
|
||||
|
||||
@@ -256,10 +256,13 @@ def get_signin_stats(ns_cookie, days=30):
|
||||
}
|
||||
|
||||
try:
|
||||
# 获取多页数据以确保覆盖指定天数
|
||||
# 获取本月第一天
|
||||
now = datetime.now()
|
||||
current_month_start = datetime(now.year, now.month, 1)
|
||||
|
||||
# 获取多页数据以确保覆盖本月所有数据
|
||||
all_records = []
|
||||
page = 1
|
||||
cutoff_date = datetime.now() - timedelta(days=days)
|
||||
|
||||
while page <= 10: # 最多查询10页,防止无限循环
|
||||
url = f"https://www.nodeseek.com/api/account/credit/page-{page}"
|
||||
@@ -273,12 +276,13 @@ def get_signin_stats(ns_cookie, days=30):
|
||||
if not records:
|
||||
break
|
||||
|
||||
# 检查最后一条记录的时间,如果超出范围就停止
|
||||
# 检查最后一条记录的时间,如果超出本月范围就停止
|
||||
last_record_time = datetime.fromisoformat(records[-1][3].replace('Z', '+00:00'))
|
||||
if last_record_time.replace(tzinfo=None) < cutoff_date:
|
||||
if last_record_time.replace(tzinfo=None) < current_month_start:
|
||||
# 只添加在本月范围内的记录
|
||||
for record in records:
|
||||
record_time = datetime.fromisoformat(record[3].replace('Z', '+00:00'))
|
||||
if record_time.replace(tzinfo=None) >= cutoff_date:
|
||||
if record_time.replace(tzinfo=None) >= current_month_start:
|
||||
all_records.append(record)
|
||||
break
|
||||
else:
|
||||
@@ -287,14 +291,14 @@ def get_signin_stats(ns_cookie, days=30):
|
||||
page += 1
|
||||
time.sleep(0.5)
|
||||
|
||||
# 筛选签到收益记录
|
||||
# 筛选本月签到收益记录
|
||||
signin_records = []
|
||||
for record in all_records:
|
||||
amount, balance, description, timestamp = record
|
||||
record_time = datetime.fromisoformat(timestamp.replace('Z', '+00:00'))
|
||||
|
||||
# 只统计指定天数内的签到收益
|
||||
if (record_time.replace(tzinfo=None) >= cutoff_date and
|
||||
# 只统计本月的签到收益
|
||||
if (record_time.replace(tzinfo=None) >= current_month_start and
|
||||
"签到收益" in description and "鸡腿" in description):
|
||||
signin_records.append({
|
||||
'amount': amount,
|
||||
@@ -308,8 +312,8 @@ def get_signin_stats(ns_cookie, days=30):
|
||||
'average': 0,
|
||||
'days_count': 0,
|
||||
'records': [],
|
||||
'period': f"最近{days}天"
|
||||
}, "查询成功,但没有找到签到记录"
|
||||
'period': f"{now.strftime('%Y年%m月')}"
|
||||
}, "查询成功,但没有找到本月签到记录"
|
||||
|
||||
# 统计数据
|
||||
total_amount = sum(record['amount'] for record in signin_records)
|
||||
@@ -321,7 +325,7 @@ def get_signin_stats(ns_cookie, days=30):
|
||||
'average': average,
|
||||
'days_count': days_count,
|
||||
'records': signin_records,
|
||||
'period': f"最近{days}天"
|
||||
'period': f"{now.strftime('%Y年%m月')}"
|
||||
}
|
||||
|
||||
return stats, "查询成功"
|
||||
@@ -420,7 +424,7 @@ if __name__ == "__main__":
|
||||
try:
|
||||
notification_msg = f"账号 {display_user} 签到成功:{msg}"
|
||||
if stats:
|
||||
notification_msg += f"\n最近30天已签到{stats['days_count']}天,共获得{stats['total_amount']}个鸡腿,平均{stats['average']}个/天"
|
||||
notification_msg += f"\n{stats['period']}已签到{stats['days_count']}天,共获得{stats['total_amount']}个鸡腿,平均{stats['average']}个/天"
|
||||
send("NodeSeek 签到", notification_msg)
|
||||
except Exception as e:
|
||||
print(f"发送通知失败: {e}")
|
||||
@@ -450,7 +454,7 @@ if __name__ == "__main__":
|
||||
try:
|
||||
notification_msg = f"账号 {display_user} 签到成功:{msg}"
|
||||
if stats:
|
||||
notification_msg += f"\n最近30天已签到{stats['days_count']}天,共获得{stats['total_amount']}个鸡腿,平均{stats['average']}个/天"
|
||||
notification_msg += f"\n{stats['period']}已签到{stats['days_count']}天,共获得{stats['total_amount']}个鸡腿,平均{stats['average']}个/天"
|
||||
send("NodeSeek 签到", notification_msg)
|
||||
except Exception as e:
|
||||
print(f"发送通知失败: {e}")
|
||||
|
||||
Reference in New Issue
Block a user