Skip to content

Commit a306a2d

Browse files
committed
Changed database download to use requests (and tqdm)
1 parent dd643a2 commit a306a2d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

pyknotid/catalogue/getdb.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,23 @@ def download_database():
7878
if exists(filen):
7979
raise IOError('A file named {} already exists.'.format(filen))
8080

81-
from urllib.request import urlretrieve
82-
urlretrieve('https://github.com/SPOCKnots/pyknotid/releases/download/init/{}'.format(db_name), filen)
81+
import requests
82+
from tqdm import tqdm
83+
# import shutil
84+
r = requests.get('https://github.com/SPOCKnots/pyknotid/releases/download/init/{}'.format(db_name),
85+
stream=True)
86+
87+
total_size = int(r.headers.get('content-length', 0))
88+
89+
with open(filen, 'wb') as f:
90+
with tqdm(total=total_size, unit='B', unit_scale=True) as pbar:
91+
for data in r.iter_content(32*1024):
92+
pbar.update(32*1024)
93+
f.write(data)
8394

8495
print('Successfully downloaded the new database file. Run '
85-
'pyknotid.clean_databases to delete old database versions.')
96+
'pyknotid.catalogue.getdb.clean_old_databases to delete '
97+
'old database versions.')
8698

8799
def clean_old_databases():
88100
'''Deletes old database files (all but the most recent version).'''

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def recursively_include(results, directory, patterns):
7575
install_requires=['numpy', 'peewee', 'vispy', 'sympy']
7676
else:
7777
install_requires=['numpy', 'networkx', 'planarity',
78-
'peewee', 'vispy', 'sympy', 'appdirs'],
78+
'peewee', 'vispy', 'sympy', 'appdirs',
79+
'requests', 'tqdm'],
7980

8081
long_description = '''
8182
Pyknotid

0 commit comments

Comments
 (0)