parent
7486e04b26
commit
4a83cd0f6f
@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
set VENV_DIR=.venv
|
||||
|
||||
if exist "%VENV_DIR%" (
|
||||
echo Activating virtual environment...
|
||||
call "%VENV_DIR%\Scripts\activate.bat"
|
||||
)
|
||||
|
||||
echo Running Python script...
|
||||
python main.py
|
||||
|
||||
if errorlevel 1 (
|
||||
echo An error occurred. Press any key to exit.
|
||||
pause >nul
|
||||
)
|
||||
|
||||
if exist "%VENV_DIR%" (
|
||||
echo Deactivating virtual environment...
|
||||
call "%VENV_DIR%\Scripts\deactivate.bat"
|
||||
)
|
@ -1,31 +1,20 @@
|
||||
import os
|
||||
from os.path import exists
|
||||
import shutil
|
||||
|
||||
|
||||
def _listdir(d): # listdir with full path
|
||||
return [os.path.join(d, f) for f in os.listdir(d)]
|
||||
|
||||
|
||||
def cleanup(id) -> int:
|
||||
def cleanup(reddit_id) -> int:
|
||||
"""Deletes all temporary assets in assets/temp
|
||||
|
||||
Returns:
|
||||
int: How many files were deleted
|
||||
"""
|
||||
if exists(f"../assets/temp/{id}/"):
|
||||
count = 0
|
||||
files = [
|
||||
f for f in os.listdir(".") if f.endswith(".mp4") and "temp" in f.lower()
|
||||
]
|
||||
count += len(files)
|
||||
for f in files:
|
||||
os.remove(f"../assets/temp/{id}/{f}")
|
||||
REMOVE_DIRS = [f"../assets/temp/{id}/mp3/", f"../assets/temp/{id}/png/"]
|
||||
for d in REMOVE_DIRS:
|
||||
if exists(d):
|
||||
count += len(_listdir(d))
|
||||
for f in _listdir(d):
|
||||
os.remove(f)
|
||||
os.rmdir(d)
|
||||
os.rmdir(f"../assets/temp/{id}/")
|
||||
return count
|
||||
directory = f"../assets/temp/{reddit_id}/"
|
||||
if exists(directory):
|
||||
shutil.rmtree(directory)
|
||||
|
||||
return 1
|
||||
|
Loading…
Reference in new issue