From 720909363829815df2a2310b469fb34a21d0db43 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 23 Sep 2021 00:10:41 -0400 Subject: [PATCH] Adjusted to account for the Clipboard folder being write protected. It couldn't be deleted, which errored everything out and stopped old files from being deleted. Also added OldFileChecker which, just checks if there are any files over 30 days old --- OldFileChecker.py | 39 +++++++++++++++++++++++++++++++++++++++ main.py | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 OldFileChecker.py diff --git a/OldFileChecker.py b/OldFileChecker.py new file mode 100644 index 0000000..f5110b6 --- /dev/null +++ b/OldFileChecker.py @@ -0,0 +1,39 @@ +import os +import time +import shutil +import logging +from twilio.rest import Client + +# Twilio Account setup +account_sid = 'AC051785f6dd5a93184641d01103eb8cd4' +auth_token = 'd40c831e56785afaa9294fd3c5a88e6e' +client = Client(account_sid, auth_token) + +# File Paths +local_path = 'C:\\BlueIris\\New\\' +remote_path = 'Y:\\' + +# Logging Setup +logging.basicConfig(filename='mover.log', format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', + level=logging.INFO) + +# Check if the mapped drive is connected +remoteOn = os.path.exists(remote_path) + +if remoteOn is True: + for file in os.listdir(remote_path): + t = os.path.getmtime(remote_path + file) + age = (time.time() -t) / 86400 + if age >= 30 and file != 'Clipboard': + print(file) + #os.remove(remote_path + file) + #logging.info('-- Deleted %s', file) +else: + print('Not connected') + logging.info(' -- Error - Server Not connected') + + message = client.messages.create( + messaging_service_sid='MG864145600a43493122488250262ccbc9', + body='Remote storage server is unavailable', + to='+14409351551' + ) \ No newline at end of file diff --git a/main.py b/main.py index 7420ea1..42eba28 100644 --- a/main.py +++ b/main.py @@ -30,7 +30,7 @@ if remoteOn is True: for file in os.listdir(remote_path): t = os.path.getmtime(remote_path + file) age = (time.time() -t) / 86400 - if age >= 30: + if age >= 30 and file != 'Clipboard': os.remove(remote_path + file) logging.info('-- Deleted %s', file) else: