download_data.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. download_file = True
  22. if os.path.exists(destination) and (os.path.getsize(destination) != file_metadata[1]):
  23. download_file = False
  24. if os.path.exists("./data") == False:
  25. os.mkdir("./data")
  26. if download_file:
  27. uri = f"{file_metadata[0]}/{token}"
  28. r = requests.get(uri, stream=True)
  29. file_size = int(int(r.headers.get('content-length'))/1000)
  30. with open(destination, "wb") as f:
  31. with Bar(f"Downloading {file_name}", max=int(file_size)) as bar:
  32. for chunck in r.iter_content(chunk_size=1024):
  33. f.write(chunck)
  34. bar.next()