download_data.py 972 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import requests
  2. from progress.bar import Bar
  3. import os
  4. import sys
  5. #
  6. # Script for MIMIC-IV project data download
  7. #
  8. # Getting command line parameter
  9. if len(sys.argv) > 1:
  10. token = sys.argv[1]
  11. file_path = {
  12. "mimic-iv.sqlite":[
  13. "http://chessm2ds.alibellamine.me:5000/",
  14. 3214753792
  15. ]
  16. }
  17. print("Downloading MIMIC-IV data")
  18. folder = "./data"
  19. for file_name, file_metadata in file_path.items():
  20. destination = "/".join([folder, file_name])
  21. if os.path.isfile(destination) == False or os.path.getsize(destination) != file_metadata[1]:
  22. uri = f"{file_metadata[0]}/{token}"
  23. r = requests.get(uri, stream=True)
  24. file_size = int(int(r.headers.get('content-length'))/1000)
  25. with open(destination, "wb") as f:
  26. with Bar(f"Downloading {file_name}", max=int(file_size)) as bar:
  27. for chunck in r.iter_content(chunk_size=1024):
  28. f.write(chunck)
  29. bar.next()