chrome-fetch.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env python3
  2. import requests
  3. import json
  4. import os.path
  5. from pprint import pprint
  6. LATEST = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json"
  7. VERFILE = "version"
  8. r = requests.get(LATEST)
  9. data = r.json()
  10. stable = data['channels']['Stable']
  11. version = stable['version']
  12. update = False
  13. # Check current version against what is available.
  14. if os.path.exists(VERFILE):
  15. with open(VERFILE, "rt") as fp:
  16. current_version = fp.readline().strip()
  17. print(f"Current version: {current_version}")
  18. if current_version != version:
  19. update = True
  20. else:
  21. update = True
  22. if update:
  23. with open(VERFILE, "wt") as fp:
  24. print(f"{version}", file=fp)
  25. print(f"Google Chrome {version}")
  26. if not update:
  27. os.sys.exit()
  28. # Ok, we need to update
  29. NEED = ("chrome", "chromedriver")
  30. grab = list()
  31. # I need chrome and chromedriver for linux64
  32. for d in stable['downloads']:
  33. if d in NEED:
  34. # Ok, that's something we need!
  35. for platform in stable['downloads'][d]:
  36. if platform['platform'] == "linux64":
  37. grab.append(platform['url'])
  38. break
  39. # Ok, lets grab some files here
  40. def download_file(url):
  41. local_filename = url.split('/')[-1]
  42. print(f"Download {url} to {local_filename}")
  43. # NOTE the stream=True parameter below
  44. with requests.get(url, stream=True) as r:
  45. r.raise_for_status()
  46. with open(local_filename, 'wb') as f:
  47. for chunk in r.iter_content(chunk_size=8192):
  48. # If you have chunk encoded response uncomment if
  49. # and set chunk_size parameter to None.
  50. #if chunk:
  51. f.write(chunk)
  52. print("Done")
  53. return local_filename
  54. for g in grab:
  55. download_file(g)
  56. # Ok, now what needs to be done?
  57. # run ./set-bin.sh script!
  58. #
  59. # unzip, remove chrome-linux64, chromedriver-linux64 directories.
  60. # pprint(stable)
  61. # pprint(grab)
  62. """
  63. {'channel': 'Stable',
  64. 'downloads': {'chrome': [{'platform': 'linux64',
  65. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/linux64/chrome-linux64.zip'},
  66. {'platform': 'mac-arm64',
  67. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/mac-arm64/chrome-mac-arm64.zip'},
  68. {'platform': 'mac-x64',
  69. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/mac-x64/chrome-mac-x64.zip'},
  70. {'platform': 'win32',
  71. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/win32/chrome-win32.zip'},
  72. {'platform': 'win64',
  73. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/win64/chrome-win64.zip'}],
  74. 'chrome-headless-shell': [{'platform': 'linux64',
  75. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/linux64/chrome-headless-shell-linux64.zip'},
  76. {'platform': 'mac-arm64',
  77. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/mac-arm64/chrome-headless-shell-mac-arm64.zip'},
  78. {'platform': 'mac-x64',
  79. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/mac-x64/chrome-headless-shell-mac-x64.zip'},
  80. {'platform': 'win32',
  81. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/win32/chrome-headless-shell-win32.zip'},
  82. {'platform': 'win64',
  83. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/win64/chrome-headless-shell-win64.zip'}],
  84. 'chromedriver': [{'platform': 'linux64',
  85. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/linux64/chromedriver-linux64.zip'},
  86. {'platform': 'mac-arm64',
  87. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/mac-arm64/chromedriver-mac-arm64.zip'},
  88. {'platform': 'mac-x64',
  89. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/mac-x64/chromedriver-mac-x64.zip'},
  90. {'platform': 'win32',
  91. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/win32/chromedriver-win32.zip'},
  92. {'platform': 'win64',
  93. 'url': 'https://storage.googleapis.com/chrome-for-testing-public/134.0.6998.35/win64/chromedriver-win64.zip'}]},
  94. 'revision': '1415337',
  95. 'version': '134.0.6998.35'}
  96. """