-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
71 lines (58 loc) · 2.29 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
from datetime import datetime
import time
import math
import shutil
import socket
def internet(host="8.8.8.8", port=53, timeout=3):
"""
Host: 8.8.8.8 (google-public-dns-a.google.com)
OpenPort: 53/tcp
Service: domain (DNS/TCP)
"""
try:
socket.setdefaulttimeout(timeout)
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
return True
except socket.error as ex:
print(ex)
return False
if internet():
pass
else:
raise Exception("There is no active internet connection. Job aborted")
current_date = datetime.today().strftime('%Y%m%d')
download_path = r"C:\Users\timing\Downloads"
files = [os.path.join(download_path, file) for file in os.listdir(download_path)]
files_size = [os.path.getsize(file) for file in files]
files_sorted = [x for _, x in sorted(zip(files_size, files))]
move_file_format = ["mp4", "wav"]
files_to_move = [file for file in files_sorted if file[-3:] in move_file_format]
files_to_check = list(set(files) - set(files_to_move))
files_to_keep = list()
for file in files_to_check:
modified_time = os.path.getmtime(file)
creation_time = os.path.getctime(file)
modified_time_in_min = math.floor(modified_time/60)
creation_time_in_min = math.floor(creation_time/60)
if modified_time_in_min == creation_time_in_min or modified_time_in_min == creation_time_in_min + 1:
files_to_move.append(file)
else:
files_to_keep.append(file)
upload_path = r"G:\My Drive\Outbox" + "\\" + current_date
if os.path.isdir(upload_path):
pass
else:
os.makedirs(upload_path, exist_ok=True)
file_itself = [f.replace(download_path + "\\", "") for f in files_to_move]
to_upload_file = [os.path.join(upload_path, f) for f in file_itself]
for download_file, upload_file in zip(files_to_move, to_upload_file):
free_size_in_gb = shutil.disk_usage("G:\\").free/(1024**3)
file_size_in_gb = os.path.getsize(download_file)/(1024**3)
print("Attempting to move " + download_file)
while file_size_in_gb > free_size_in_gb:
print("Not enough buffer space in the disk, reattempting in 1 minute")
print("File size (GB): " + str(file_size_in_gb))
print("Free space (GB): " + str(free_size_in_gb))
time.sleep(60)
shutil.move(download_file, upload_file)