代码拉取完成,页面将自动刷新
同步操作将从 WKC/sazs34-MyActions 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import requests
import os
import re
import time
from datetime import datetime
from dateutil import tz
def loadFileContent(downloadUrl):
return requests.get(downloadUrl).text
def writeFile(content, fileName):
file = './'+fileName
with open(file, 'w', encoding='utf-8') as f:
f.write(content.replace('\r\n', '\n'))
def safe_cast(val, to_type, default=None):
try:
return to_type(val)
except (ValueError, TypeError):
return default
def readSecret(key):
if key in os.environ and not os.environ[key].strip() == '':
return os.environ[key]
else:
return None
def isOver():
hourLimit = readSecret("XMLY_ACCUMULATE_HOURS")
print("HOURS:"+str(safe_cast(hourLimit, int, -1)))
if not hourLimit is None and safe_cast(hourLimit, int, 0) > 0:
date_stamp = (int(time.time())-57600) % 86400
print(datetime.now(tz=tz.gettz('Asia/Shanghai')
).strftime("%Y-%m-%d %H:%M:%S", ))
print("今日已过秒数: ", date_stamp)
if date_stamp > int(hourLimit) * 60 * 60:
return True
else:
return False
else:
print("未配置XMLY_ACCUMULATE_HOURS,因此不会对执行时长进行限制")
return False
def isJumpIndex(idx):
indexLimit = readSecret("XMLY_ACCUMULATE_INDEX")
if indexLimit is None:
return False
xmly_accumulate_index = [safe_cast(i, int, -1)
for i in indexLimit.split(",")]
if len(xmly_accumulate_index) <= 0:
xmly_accumulate_index = None
index = -1
try:
index = xmly_accumulate_index.index(idx+1)
except ValueError:
print("无需禁用")
return index >= 0
def smartNotify(content):
notify_bark = readSecret("BARK_PUSH")
notify_serverJ = readSecret("PUSH_KEY")
if not content:
return content
if notify_bark is not None:
print("bark通知已开启")
content = content.replace(
'bark_token = BARK', 'bark_token="'+notify_bark+'"', 1)
if notify_serverJ is not None:
print("server酱通知已开启")
content = content.replace(
'sckey = SCKEY', 'sckey="'+notify_serverJ+'"', 1)
# only for test
# content = content.replace(
# 'if _notify_time.split()[0] == str(notify_time) and int(_notify_time.split()[1]) > 30:', 'if True:', 1)
return content
def run():
cookies = readSecret("XMLY_SPEED_COOKIE")
if cookies is None:
print("无法获取Cookie,请在Secrets中配置XMLY_SPEED_COOKIE")
return
print("\n同步文件中...")
webFileContent = loadFileContent(os.environ["SYNCURL"])
print("\n文件同步完毕, 处理中...")
agentPattern = re.compile(r'UserAgent = \"[\d\D]*?\"', re.S)
rewriteAgent = readSecret("XMLY_ANDROID_AGENT")
if rewriteAgent is None:
rewriteAgent = 'UserAgent = "ting_1.8.30(Redmi+7,Android28)"'
else:
rewriteAgent = 'UserAgent = "' + rewriteAgent + '"'
for idx, xmlyCookie in enumerate(cookies.split('\n')):
executeContent = webFileContent.replace(
'xmly_speed_cookie = os.environ["XMLY_SPEED_COOKIE"]', 'xmly_speed_cookie = "' + xmlyCookie + '"', 1)
if xmlyCookie.find("_device=android") > 0: # 此时表示是获取的安卓的cookie,需要使用安卓的agent
executeContent = re.sub(agentPattern, rewriteAgent, executeContent)
if isOver():
executeContent = executeContent.replace(
"XMLY_ACCUMULATE_TIME = 1", "XMLY_ACCUMULATE_TIME = 0", 1)
print("XMLY_ACCUMULATE_HOURS配置生效,索引" +
str(idx)+"的数据执行了禁用当天继续刷新时长的操作")
if isJumpIndex(idx+1):
executeContent = executeContent.replace(
"XMLY_ACCUMULATE_TIME = 1", "XMLY_ACCUMULATE_TIME = 0", 1)
print("XMLY_ACCUMULATE_INDEX配置生效,为索引" +
str(idx)+"的数据执行了禁用当天刷新时长的操作")
executeContent = smartNotify(executeContent)
writeFile(executeContent, 'execute'+str(idx)+'.py')
os.system('python ./'+'execute'+str(idx)+'.py')
print("\n***************************\n文件全部执行完毕")
exit(0)
run()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。