Browse Source

Update README.md

pull/15/head
yuxian158 3 years ago
parent
commit
ce9077fb1c
  1. 52
      utils.py

52
utils.py

@ -200,46 +200,28 @@ class check(object):
return wrapper return wrapper
@check(run_script_name="随机定时", run_script_expression="QL_RANDOM_TIME", Configuration_flag=True) def change_cron(cron_file_path="/ql/db/crontab.db",repositories="yuxian158_check"):
def change_db(): def change_time(time_str: str):
words = re.sub("\\s+", " ", time_str).split()
words[0] = str(random.randrange(60))
words[1] = str(random.randrange(22))
return " ".join(words)
time_str = time.strftime("%Y-%m-%d", time.localtime())
os.system(f"cp /ql/db/crontab.db /ql/db/crontab.db.{time_str}.back")
lines = [] lines = []
first = True with open(cron_file_path, "r" ,encoding="UTF-8") as f:
with open("/ql/db/crontab.db", "r", encoding="UTF-8") as f:
for i in f.readlines(): for i in f.readlines():
if ( # print(record.get("command"))
i.find("yuxian158_check_master") != -1 if i.find(repositories) != -1:
and i.find("ran_time") == -1
):
record = json.loads(i) record = json.loads(i)
if record.get("isDisabled") == 0: record["schedule"] = change_time(record["schedule"])
if (
i.find("motto") != -1
or i.find("leetcode") != -1
or i.find("weather") != -1
or i.find("news") != -1
):
record["schedule"] = change_time(record["schedule"], True)
else:
record["schedule"] = change_time(record["schedule"], first)
if first:
first = False
lines.append(json.dumps(record, ensure_ascii=False) + "\n") lines.append(json.dumps(record, ensure_ascii=False) + "\n")
else: else:lines.append(i)
lines.append(i)
time_str = time.strftime("%Y-%m-%d", time.localtime()) with open(cron_file_path, "w", encoding="UTF-8") as f:
os.system(f"copy /ql/db/crontab.db /ql/db/crontab.db.{time_str}.back")
with open("/ql/db/crontab.db", "w", encoding="UTF-8") as f:
f.writelines(lines) f.writelines(lines)
def change_time(time_str: str, first: bool): if __name__ == "__main__":
words = re.sub("\\s+", " ", time_str).split() change_cron()
if first:
words[0] = str(random.randrange(0, 60, step=5))
words[1] = str(random.randrange(8, 9))
else:
words[0] = str(random.randrange(60))
words[1] = str(random.randrange(22))
return " ".join(words)

Loading…
Cancel
Save