Skip to content

Commit

Permalink
Changed database download to use requests (and tqdm)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclement committed Sep 5, 2017
1 parent dd643a2 commit a306a2d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
18 changes: 15 additions & 3 deletions pyknotid/catalogue/getdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,23 @@ def download_database():
if exists(filen):
raise IOError('A file named {} already exists.'.format(filen))

from urllib.request import urlretrieve
urlretrieve('https://github.com/SPOCKnots/pyknotid/releases/download/init/{}'.format(db_name), filen)
import requests
from tqdm import tqdm
# import shutil
r = requests.get('https://github.com/SPOCKnots/pyknotid/releases/download/init/{}'.format(db_name),
stream=True)

total_size = int(r.headers.get('content-length', 0))

with open(filen, 'wb') as f:
with tqdm(total=total_size, unit='B', unit_scale=True) as pbar:
for data in r.iter_content(32*1024):
pbar.update(32*1024)
f.write(data)

print('Successfully downloaded the new database file. Run '
'pyknotid.clean_databases to delete old database versions.')
'pyknotid.catalogue.getdb.clean_old_databases to delete '
'old database versions.')

def clean_old_databases():
'''Deletes old database files (all but the most recent version).'''
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def recursively_include(results, directory, patterns):
install_requires=['numpy', 'peewee', 'vispy', 'sympy']
else:
install_requires=['numpy', 'networkx', 'planarity',
'peewee', 'vispy', 'sympy', 'appdirs'],
'peewee', 'vispy', 'sympy', 'appdirs',
'requests', 'tqdm'],

long_description = '''
Pyknotid
Expand Down

0 comments on commit a306a2d

Please sign in to comment.