Untitled
unknown
plain_text
2 years ago
1.4 kB
4
Indexable
import os import zipfile import datetime path = '/volume1/Public Clouds/Google Drive/Audio/Economist Audiobooks' def zip_directory(path, zip_name): with zipfile.ZipFile(path + "/" + zip_name, 'w') as myzip: for root, dirs, files in os.walk(path): for file in files: myzip.write(os.path.join(root, file)) print("Zip file created.") now = datetime.datetime.now() # Check if a zip file has been created in the past hour zip_files = [f for f in os.listdir(path) if f.endswith('.zip')] zip_creation_time = datetime.datetime.fromtimestamp(os.path.getctime(path + "/" + zip_files[0])) if zip_files else None if zip_creation_time and (now - zip_creation_time).seconds < 3600: print("A zip file has been created in the past hour.") else: print("A zip file has not been created in the past hour.") # Find directories modified between 5 minutes and 90 minutes ago for root, dirs, files in os.walk(path): for dir in dirs: dir_mod_time = datetime.datetime.fromtimestamp(os.path.getmtime(os.path.join(root, dir))) if (now - dir_mod_time).seconds > 300 and (now - dir_mod_time).seconds < 5400: zip_directory(os.path.join(root, dir), now.strftime("%m-%d-%Y") + '_EconMP3.zip') break else: print("No directory found that was modified between 5 minutes and 90 minutes ago.")
Editor is loading...