Removing the tar process and now deleting cdx.json files older than 24 hours

This commit is contained in:
datechnoman 2024-01-09 05:45:25 +00:00
parent 49a9bc4710
commit 51c127601a

View File

@ -2,7 +2,6 @@
import os import os
import subprocess import subprocess
import json import json
import tarfile # Use tarfile for creating tar archives
from datetime import datetime, timedelta from datetime import datetime, timedelta
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from urllib.parse import urlparse from urllib.parse import urlparse
@ -184,11 +183,8 @@ def main():
for filename in os.listdir(MEDIAFIRE_DIRECTORY): for filename in os.listdir(MEDIAFIRE_DIRECTORY):
file_path = os.path.join(MEDIAFIRE_DIRECTORY, filename) file_path = os.path.join(MEDIAFIRE_DIRECTORY, filename)
if filename.endswith(".cdx.json") and os.path.getmtime(file_path) < older_than_24_hours.timestamp(): if filename.endswith(".cdx.json") and os.path.getmtime(file_path) < older_than_24_hours.timestamp():
# Appending to the existing tar file
with tarfile.open(os.path.join(MEDIAFIRE_DIRECTORY, 'mediafire_cdxfiles_archive.tar'), 'a') as tar:
tar.add(file_path, arcname=filename)
os.remove(file_path) os.remove(file_path)
print(f"Added '{filename}' to 'mediafire_cdxfiles_archive.tar' and removed the JSON file.") print(f"Deleted '{filename}' as it is older than 24 hours.")
run_ia_command() # Run IA command after processing older files run_ia_command() # Run IA command after processing older files