-
Notifications
You must be signed in to change notification settings - Fork 0
/
DownloadProcess.py
30 lines (26 loc) · 1.09 KB
/
DownloadProcess.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
from multiprocessing import Process
from time import sleep
import urllib.request
__author__ = 'Maxi'
class DownloadProcess(Process):
def __init__(self, url, username, password, downloadSemaphore):
super(DownloadProcess, self).__init__()
self.url = url
self.username = username
self.password = password
self.downloadSemaphore = downloadSemaphore
def download(self):
# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password('softq',self.url,self.username,self.password)
opener = urllib.request.build_opener(auth_handler)
dat = opener.open(self.url)
#Find file name of file
filename = self.url.rpartition('/')[2]
file = open('soft/'+filename, 'wb')
file.write(dat.read())
file.close()
def run(self):
self.downloadSemaphore.acquire()
self.download()
self.downloadSemaphore.release()