CommonService.py 800 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
  5. @AUTHOR: ASJRD018
  6. @NAME: langer
  7. @software: PyCharm
  8. @DATE: 2019/9/4 17:18
  9. @Version: python3.6
  10. @MODIFY DECORD:ansjer dev
  11. @file: CommonService.py
  12. @Contact: chanjunkai@163.com
  13. """
  14. import hashlib
  15. from urllib.request import urlopen
  16. # 通过url获取文件md5
  17. class CommonService:
  18. @staticmethod
  19. def get_remote_md5_sum(url, max_file_size=100 * 1024 * 1024):
  20. remote = urlopen(url)
  21. hash = hashlib.md5()
  22. total_read = 0
  23. while True:
  24. data = remote.read(4096)
  25. total_read += 4096
  26. if not data or total_read > max_file_size:
  27. break
  28. hash.update(data)
  29. return hash.hexdigest()