Skip to content

Commit

Permalink
added additional attempt to clean up leftover image folders
Browse files Browse the repository at this point in the history
  • Loading branch information
9FS committed Sep 25, 2023
1 parent d312572 commit cf817fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = "MIT"
name = "x" # can't leave empty because of bug with `poetry install` from poetry.lock file
readme = "readme.md"
repository = "https://github.com/9-FS/2021-11-15-nHentai-to-PDF"
version = "1.0.0"
version = "1.0.1"

[tool.poetry.dependencies]
kfsconfig = "^1.0.0"
Expand Down
14 changes: 14 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from KFSfstr import KFSfstr
from KFSlog import KFSlog
import logging
import os
from get_hentai_ID_list import get_hentai_ID_list
from Hentai import Hentai


@KFSlog.timeit
def main():
cleanup_success: bool=True #cleanup successful
COOKIES_DEFAULT: str=json.dumps({
"cf_clearance": "",
"csrftoken": "",
Expand Down Expand Up @@ -38,4 +40,16 @@ def main():
hentai.download() # download hentai
logging.info("--------------------------------------------------")


logging.info("Removing leftover image folders...")
for hentai_ID in hentai_ID_list: # attempt final cleanup
if os.path.isdir(f"./hentai/{hentai_ID}") and len(os.listdir(f"./hentai/{hentai_ID}"))==0: # if cache folder still exists and is empty:
try:
os.rmdir(f"./hentai/{hentai_ID}") # try to clean up
except PermissionError: # may fail if another process is still using directory like dropbox
logging.warning(f"Removing \"./hentai/{hentai_ID}\" failed with PermissionError.")
cleanup_success=False # cleanup unsuccessful
if cleanup_success==True:
logging.info("\rRemoved leftover image folders.")

return

0 comments on commit cf817fa

Please sign in to comment.