Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新建线程以检查旧截图 #678

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions arknights_mower/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import time
import traceback
import threading
from logging.handlers import RotatingFileHandler
from pathlib import Path

Expand Down Expand Up @@ -31,7 +32,6 @@ def filter(self, record: logging.LogRecord) -> bool:

filter = PackagePathFilter()


logger = logging.getLogger(__name__)
logger.setLevel("DEBUG")

Expand Down Expand Up @@ -72,15 +72,22 @@ def save_screenshot(img: bytes) -> None:
folder = get_path("@app/screenshot")
folder.mkdir(exist_ok=True, parents=True)
time_ns = time.time_ns()
start_time_ns = time_ns - config.conf.screenshot * 3600 * 10**9
start_time_ns = time_ns - config.conf.screenshot * 3600 * 10 ** 9
checking_thread = threading.Thread(target=check_old_screenshot,
kwargs={"start_time_ns": start_time_ns,
"folder": folder})
checking_thread.start()
filename = f"{time_ns}.jpg"
with folder.joinpath(filename).open("wb") as f:
f.write(img)
logger.debug(f"save screenshot: {filename}")


def check_old_screenshot(start_time_ns, folder):
for i in folder.iterdir():
if i.is_dir():
shutil.rmtree(i)
elif not i.stem.isnumeric():
i.unlink()
elif int(i.stem) < start_time_ns:
i.unlink()
filename = f"{time_ns}.jpg"
with folder.joinpath(filename).open("wb") as f:
f.write(img)
logger.debug(f"save screenshot: {filename}")
Loading