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.

40 lines
1.1 KiB

6 years ago
  1. import requests
  2. import os
  3. import tarfile
  4. import sys,getpass
  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. paths = ["../server_side/api/modules", "."]
  9. for i in range(len(urls)):
  10. url = urls[i]
  11. print("[INFO]: Downloading file: {} to temp.tar.gz!".format(url.split("/")[-1]))
  12. with open("temp.tar.gz", 'wb') as f:
  13. response = requests.get(url, stream=True)
  14. total = response.headers.get('content-length')
  15. if total is None:
  16. f.write(response.content)
  17. else:
  18. downloaded = 0
  19. total = int(total)
  20. for data in response.iter_content(chunk_size=max(int(total/1000), 1024*1024)):
  21. downloaded += len(data)
  22. f.write(data)
  23. done = int(50*downloaded/total)
  24. sys.stdout.write('\r[{}{}]'.format('*' * done, '.' * (50-done)))
  25. sys.stdout.flush()
  26. sys.stdout.write('\n')
  27. print("[INFO]: Done downloading, now extracting!")
  28. tar = tarfile.open("temp.tar.gz")
  29. tar.extractall(path=paths[i])
  30. tar.close()
  31. os.remove("temp.tar.gz")
  32. print("[INFO]: Done downloading, now deleting!")
  33. print("[INFO]: Done")