You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

  1. import requests
  2. import os
  3. import tarfile
  4. import sys
  5. urls = ["https://s3-ap-northeast-1.amazonaws.com/mycityreport/trainedModels.tar.gz",
  6. "http://download.tensorflow.org/models/object_detection/rfcn_resnet101_coco_2018_01_28.tar.gz"]
  7. paths = ["../server_side/api/modules", "."]
  8. for i in range(len(urls)):
  9. url = urls[i]
  10. print("[INFO]: Downloadinng file: {} to temp.tar.gz!".format(url.split("/")[-1]))
  11. with open("temp.tar.gz", 'wb') as f:
  12. response = requests.get(url, stream=True)
  13. total = response.headers.get('content-length')
  14. if total is None:
  15. f.write(response.content)
  16. else:
  17. downloaded = 0
  18. total = int(total)
  19. for data in response.iter_content(chunk_size=max(int(total/1000), 1024*1024)):
  20. downloaded += len(data)
  21. f.write(data)
  22. done = int(50*downloaded/total)
  23. sys.stdout.write('\r[{}{}]'.format('*' * done, '.' * (50-done)))
  24. sys.stdout.flush()
  25. sys.stdout.write('\n')
  26. print("[INFO]: Done downloading, now extracting!")
  27. tar = tarfile.open("temp.tar.gz")
  28. tar.extractall(path=paths[i])
  29. tar.close()
  30. os.remove("temp.tar.gz")
  31. print("[INFO]: Done downloading, now deleting!")
  32. print("[INFO]: Done")