Created
August 12, 2018 21:38
-
-
Save vehrka/38ff1b20cb59c1a1f1c6a38d4ed5bd42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import requests | |
import json | |
import os | |
base_url = 'https://www.humblebundle.com/api/v1/order/{download_key}' | |
# Get this one from the bundle page url | |
download_key = '' | |
# Get this one inspecting the headers of the bundle page | |
cookie_auth = {'_simpleauth_sess': ''} | |
url = base_url.format(download_key=download_key) | |
os.makedirs(download_key, exist_ok=False) | |
r = requests.get(url, cookies=cookie_auth) | |
data = json.loads(r.text) | |
subproducts = [sub for sub in data['subproducts'] if len(sub['downloads']) > 0] | |
for subp in subproducts: | |
for book in subp['downloads']: | |
book_name = book['machine_name'] | |
print(book_name) | |
for struct in book['download_struct']: | |
try: | |
url_down = struct['url']['web'] | |
file_name = url_down.split('?')[0].split('/')[-1] | |
comp_file_name = os.path.join(download_key, file_name) | |
r_pdf = requests.get(url_down, stream=True) | |
handle = open(comp_file_name, 'wb') | |
for chunk in r_pdf.iter_content(chunk_size=512): | |
if chunk: # filter out keep-alive new chunks | |
handle.write(chunk) | |
except KeyError: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment