Update print.py
Browse files
print.py
CHANGED
@@ -1,37 +1,25 @@
|
|
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 |
-
|
11 |
-
with open(SETTINGS_FILE, 'r') as file:
|
12 |
content = file.read()
|
13 |
-
|
14 |
-
|
15 |
-
|
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 |
-
|
28 |
-
|
29 |
-
|
30 |
-
log_file.write(error_message)
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
interval = 10 # 时间间隔,单位为秒(1小时)
|
35 |
while True:
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
1 |
import time
|
|
|
2 |
|
3 |
+
def read_and_print_file():
|
|
|
|
|
|
|
|
|
4 |
try:
|
5 |
+
with open('/etc/searxng/settings.yml', 'r') as file:
|
|
|
6 |
content = file.read()
|
7 |
+
print("File Content:\n", content)
|
8 |
+
except FileNotFoundError:
|
9 |
+
print("Error: File '/etc/searxng/settings.yml' not found.")
|
10 |
+
except PermissionError:
|
11 |
+
print("Error: Permission denied to read the file.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
except Exception as e:
|
13 |
+
print(f"An unexpected error occurred: {e}")
|
14 |
+
|
15 |
+
# 定时运行
|
16 |
+
interval = 600 # 设置间隔时间(单位:秒),例如 600 秒(10 分钟)
|
|
|
17 |
|
18 |
+
print("Starting task. Press Ctrl+C to stop.")
|
19 |
+
try:
|
|
|
20 |
while True:
|
21 |
+
read_and_print_file()
|
22 |
+
print(f"Sleeping for {interval} seconds...")
|
23 |
+
time.sleep(interval)
|
24 |
+
except KeyboardInterrupt:
|
25 |
+
print("\nTask stopped.")
|