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): @@ -200,46 +200,28 @@ class check(object):
return wrapper
@check(run_script_name="随机定时", run_script_expression="QL_RANDOM_TIME", Configuration_flag=True)
def change_db():
def change_cron(cron_file_path="/ql/db/crontab.db",repositories="yuxian158_check"):
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 = []
first = True
with open("/ql/db/crontab.db", "r", encoding="UTF-8") as f:
with open(cron_file_path, "r" ,encoding="UTF-8") as f:
for i in f.readlines():
if (
i.find("yuxian158_check_master") != -1
and i.find("ran_time") == -1
):
# print(record.get("command"))
if i.find(repositories) != -1:
record = json.loads(i)
if record.get("isDisabled") == 0:
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
record["schedule"] = change_time(record["schedule"])
lines.append(json.dumps(record, ensure_ascii=False) + "\n")
else:
lines.append(i)
else:lines.append(i)
time_str = time.strftime("%Y-%m-%d", time.localtime())
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:
with open(cron_file_path, "w", encoding="UTF-8") as f:
f.writelines(lines)
def change_time(time_str: str, first: bool):
words = re.sub("\\s+", " ", time_str).split()
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)
if __name__ == "__main__":
change_cron()

Loading…
Cancel
Save