-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_readme.py
45 lines (34 loc) · 1.11 KB
/
update_readme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import datetime
readme_file = "README.md"
now = datetime.datetime.now()
state_file = "last_state.txt"
if os.path.exists(state_file):
with open(state_file, "r") as f:
last_state = f.read().strip()
else:
last_state = "minus"
if last_state == "minus":
new_time = now + datetime.timedelta(minutes=1)
new_state = "plus"
else:
new_time = now - datetime.timedelta(minutes=1)
new_state = "minus"
with open(state_file, "w") as f:
f.write(new_state)
current_time = new_time.strftime("%Y-%m-%d %H:%M:%S")
update_message = f"\nREADME updated automatically on: {current_time} - Alternating between adding or subtracting a minute each day.\n"
with open(readme_file, "r") as file:
readme_content = file.readlines()
updated_content = []
updated = False
for line in readme_content:
if line.startswith("README updated automatically on"):
updated_content.append(update_message)
updated = True
else:
updated_content.append(line)
if not updated:
updated_content.append(update_message)
with open(readme_file, "w") as file:
file.writelines(updated_content)