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
|
import os
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
def _listdir(d): # listdir with full path
|
def _listdir(d): # listdir with full path
|
||||||
return [os.path.join(d, f) for f in os.listdir(d)]
|
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
|
"""Deletes all temporary assets in assets/temp
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: How many files were deleted
|
int: How many files were deleted
|
||||||
"""
|
"""
|
||||||
if exists(f"../assets/temp/{id}/"):
|
directory = f"../assets/temp/{reddit_id}/"
|
||||||
count = 0
|
if exists(directory):
|
||||||
files = [
|
shutil.rmtree(directory)
|
||||||
f for f in os.listdir(".") if f.endswith(".mp4") and "temp" in f.lower()
|
|
||||||
]
|
return 1
|
||||||
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
|
|
||||||
|
Loading…
Reference in new issue