-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload_files.py
29 lines (21 loc) · 968 Bytes
/
download_files.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
import urllib.request
import os
import gzip
import shutil
class FileDownloader:
def single_file(self, source):
if source == 'string_edges':
# check to see if file already exists
# TODO: check file version too
file = os.path.join('data', 'input_files', 'string_edges.txt.gz')
if os.path.exists(file):
return None
url = 'http://viruses.string-db.org/download/protein.links.full.v10.5.txt.gz'
print('Downloading file from: ' + url)
# download file
urllib.request.urlretrieve(url, os.path.join('data', 'input_files', 'string_edges.txt.gz'))
# unzip
with gzip.open(os.path.join('data', 'input_files', 'string_edges.txt.gz'), 'rb') as f_in:
with open(os.path.join('data', 'input_files', 'string_edges.txt'), 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
print('Done!')