Create print.py
Browse files
print.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
from datetime import datetime
|
3 |
+
|
4 |
+
# 定义日志文件路径
|
5 |
+
LOG_FILE = "/var/log/searxng_settings.log"
|
6 |
+
SETTINGS_FILE = "/etc/searxng/settings.yml"
|
7 |
+
|
8 |
+
def log_settings():
|
9 |
+
try:
|
10 |
+
# 读取 settings.yml 文件内容
|
11 |
+
with open(SETTINGS_FILE, 'r') as file:
|
12 |
+
content = file.read()
|
13 |
+
|
14 |
+
# 记录当前时间和内容到日志
|
15 |
+
timestamp = f"====================\nTimestamp: {datetime.now()}\n====================\n"
|
16 |
+
|
17 |
+
# 打印到控制台
|
18 |
+
print(timestamp)
|
19 |
+
print(content)
|
20 |
+
|
21 |
+
# 写入日志文件
|
22 |
+
with open(LOG_FILE, 'a') as log_file:
|
23 |
+
log_file.write(timestamp)
|
24 |
+
log_file.write(content + "\n\n")
|
25 |
+
except Exception as e:
|
26 |
+
# 错误处理
|
27 |
+
error_message = f"Error at {datetime.now()}: {e}\n"
|
28 |
+
print(error_message)
|
29 |
+
with open(LOG_FILE, 'a') as log_file:
|
30 |
+
log_file.write(error_message)
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
# 定时任务
|
34 |
+
interval = 3600 # 时间间隔,单位为秒(1小时)
|
35 |
+
while True:
|
36 |
+
log_settings()
|
37 |
+
time.sleep(interval)
|