Skip to content

Instantly share code, notes, and snippets.

@peterbe
Created June 21, 2018 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterbe/e48ef24d59ea3d5ae37173c95cf94d72 to your computer and use it in GitHub Desktop.
Save peterbe/e48ef24d59ea3d5ae37173c95cf94d72 to your computer and use it in GitHub Desktop.
import requests
import os
import subprocess
url = 'http://ftp.stage.mozaws.net/pub/firefox/candidates/61.0b15-candidates/build9/win64/en-US/buildhub.json'
stuff = requests.get(url).json()
# print(stuff['download'])
download_url = stuff['download']['url']
r = requests.get(download_url, stream=True)
filename = os.path.basename(download_url)
with open(filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
# print(r.headers)
print('JSON SIZE', stuff['download']['size'])
print('OS SIZE ', os.stat(filename).st_size)
print('JSON MIME', stuff['download']['mimetype'])
mime = subprocess.check_output(['mime', filename]).decode('utf-8').strip()
print('OS MIME ', mime)
@peterbe
Copy link
Author

peterbe commented Jun 21, 2018

Output when I run this:

▶ p3 ~/dev/MOZILLA/BUILDHUB/download-check.py
JSON SIZE 40992536
OS SIZE   40992536
JSON MIME application/octet-stream
OS MIME   application/octet-stream

@lisajguo
Copy link

Woohoo!

@MihaiTabara
Copy link

🎼 to my 👂 👂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment