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.

43 lines
1.3 KiB

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