def download_book_crossings(target_dir):
 archive_path = os.path.join(target_dir, ARCHIVE_NAME)
 if (not os.path.exists(target_dir)):
  os.makedirs(target_dir)
 if (not os.path.exists(archive_path)):
  logger.warn('Downloading dataset from %s (77 MB)', URL)
  opener = urllib.urlopen(URL)
  open(archive_path, 'wb').write(opener.read())
 logger.info('Decompressing %s', archive_path)
 source_zip = zipfile.ZipFile(archive_path, 'r')
 archives = []
 for name in source_zip.namelist():
  if (name.find('.csv') != (-1)):
   source_zip.extract(name, target_dir)
   archives.append(name)
 source_zip.close()
 os.remove(archive_path)
 return archives

def download_book_crossings ( target_dir ) : archive_path = os . path . join ( target_dir , ARCHIVE_NAME ) if ( not os . path . exists ( target_dir ) ) : os . makedirs ( target_dir ) if ( not os . path . exists ( archive_path ) ) : logger . warn ( 'Downloading dataset from %s (77 MB)' , URL ) opener = urllib . urlopen ( URL ) open ( archive_path , 'wb' ) . write ( opener . read ( ) ) logger . info ( 'Decompressing %s' , archive_path ) source_zip = zipfile . ZipFile ( archive_path , 'r' ) archives = [ ] for name in source_zip . namelist ( ) : if ( name . find ( '.csv' ) != ( - 1 ) ) : source_zip . extract ( name , target_dir ) archives . append ( name ) source_zip . close ( ) os . remove ( archive_path ) return archives
download the book-crossing data and unzip it .