mirror of
https://github.com/tcsenpai/pensieve.git
synced 2025-06-07 03:35:24 +00:00
chore: use logging instead of print
This commit is contained in:
parent
a76adde798
commit
36c4bf7c5f
@ -1,3 +1,5 @@
|
|||||||
|
import logging
|
||||||
|
import datetime
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
@ -15,6 +17,9 @@ import ctypes
|
|||||||
import ctypes.wintypes
|
import ctypes.wintypes
|
||||||
from screeninfo import get_monitors
|
from screeninfo import get_monitors
|
||||||
|
|
||||||
|
# 在文件开头添加日志配置
|
||||||
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
def get_monitor_info():
|
def get_monitor_info():
|
||||||
return {monitor.name: monitor for monitor in get_monitors()}
|
return {monitor.name: monitor for monitor in get_monitors()}
|
||||||
|
|
||||||
@ -57,7 +62,7 @@ def take_screenshot(base_dir, previous_hashes, threshold, screen_sequences, date
|
|||||||
for i, monitor in enumerate(sct.monitors[1:], 1): # Skip the first full-screen monitor
|
for i, monitor in enumerate(sct.monitors[1:], 1): # Skip the first full-screen monitor
|
||||||
monitor_name = monitor_infos.get(f"\\\\.\\DISPLAY{i}", f"screen_{i}").name
|
monitor_name = monitor_infos.get(f"\\\\.\\DISPLAY{i}", f"screen_{i}").name
|
||||||
safe_monitor_name = ''.join(c for c in monitor_name if c.isalnum() or c in ('_', '-'))
|
safe_monitor_name = ''.join(c for c in monitor_name if c.isalnum() or c in ('_', '-'))
|
||||||
print(f"Processing monitor: {safe_monitor_name}") # Debug output
|
logging.info(f"Processing monitor: {safe_monitor_name}") # Debug output
|
||||||
|
|
||||||
jpeg_filename = os.path.join(base_dir, date, f"screenshot-{timestamp}-of-{safe_monitor_name}.jpg")
|
jpeg_filename = os.path.join(base_dir, date, f"screenshot-{timestamp}-of-{safe_monitor_name}.jpg")
|
||||||
|
|
||||||
@ -69,7 +74,7 @@ def take_screenshot(base_dir, previous_hashes, threshold, screen_sequences, date
|
|||||||
|
|
||||||
# Check if current screenshot is similar to the previous one
|
# Check if current screenshot is similar to the previous one
|
||||||
if safe_monitor_name in previous_hashes and current_hash - previous_hashes[safe_monitor_name] < threshold:
|
if safe_monitor_name in previous_hashes and current_hash - previous_hashes[safe_monitor_name] < threshold:
|
||||||
print(f"Screenshot for {safe_monitor_name} is similar to the previous one. Skipping.")
|
logging.info(f"Screenshot for {safe_monitor_name} is similar to the previous one. Skipping.")
|
||||||
worklog.write(
|
worklog.write(
|
||||||
f"{timestamp} - {safe_monitor_name} - Skipped (similar to previous)\n"
|
f"{timestamp} - {safe_monitor_name} - Skipped (similar to previous)\n"
|
||||||
)
|
)
|
||||||
@ -134,11 +139,11 @@ def main():
|
|||||||
timestamp,
|
timestamp,
|
||||||
)
|
)
|
||||||
for screenshot_file in screenshot_files:
|
for screenshot_file in screenshot_files:
|
||||||
print(f"Screenshot taken: {screenshot_file}")
|
logging.info(f"Screenshot taken: {screenshot_file}")
|
||||||
else:
|
else:
|
||||||
print("Screen is locked. Skipping screenshot.")
|
logging.info("Screen is locked. Skipping screenshot.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An error occurred: {str(e)}. Skipping this iteration.")
|
logging.error(f"An error occurred: {str(e)}. Skipping this iteration.")
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
from AppKit import NSWorkspace
|
from AppKit import NSWorkspace
|
||||||
@ -14,6 +15,8 @@ import imagehash
|
|||||||
import argparse
|
import argparse
|
||||||
from memos.utils import write_image_metadata
|
from memos.utils import write_image_metadata
|
||||||
|
|
||||||
|
# 在文件开头添加日志配置
|
||||||
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
def get_active_window_info():
|
def get_active_window_info():
|
||||||
active_app = NSWorkspace.sharedWorkspace().activeApplication()
|
active_app = NSWorkspace.sharedWorkspace().activeApplication()
|
||||||
@ -98,9 +101,7 @@ def take_screenshot(
|
|||||||
screen_name in previous_hashes
|
screen_name in previous_hashes
|
||||||
and current_hash - previous_hashes[screen_name] < threshold
|
and current_hash - previous_hashes[screen_name] < threshold
|
||||||
):
|
):
|
||||||
print(
|
logging.info(f"Screenshot for {screen_name} is similar to the previous one. Skipping.")
|
||||||
f"Screenshot for {screen_name} is similar to the previous one. Skipping."
|
|
||||||
)
|
|
||||||
os.remove(temp_filename)
|
os.remove(temp_filename)
|
||||||
# 记录跳过的截图
|
# 记录跳过的截图
|
||||||
worklog.write(
|
worklog.write(
|
||||||
@ -176,11 +177,11 @@ def main():
|
|||||||
timestamp,
|
timestamp,
|
||||||
)
|
)
|
||||||
for screenshot_file in screenshot_files:
|
for screenshot_file in screenshot_files:
|
||||||
print(f"Screenshot taken: {screenshot_file}")
|
logging.info(f"Screenshot taken: {screenshot_file}")
|
||||||
else:
|
else:
|
||||||
print("Screen is locked. Skipping screenshot.")
|
logging.info("Screen is locked. Skipping screenshot.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An error occurred: {str(e)}. Skipping this iteration.")
|
logging.error(f"An error occurred: {str(e)}. Skipping this iteration.")
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user