Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update trove_order.py to reflect latest API (joining on #15 and #32) #20

Open
wants to merge 2 commits into
base: poc-trove
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions humble_downloader/humble_api/model/trove_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .subproduct import Subproduct
from .product import Product
from sys import stderr
import json


class TroveOrder(Order):
Expand All @@ -28,29 +29,33 @@ def __init__(self, trove_page_html_text, hapi):
return

tree = lxml.html.fromstring(trove_page_html_text)
trove_products = tree.find_class("trove-product-detail")
trove_data_element = tree.get_element_by_id("webpack-monthly-trove-data")
trove_raw_json = trove_data_element.text_content()
trove_json_obj = json.loads(trove_raw_json)

subproducts = []
for product_lxml in trove_products:
if len(product_lxml.find_class('js-download-button')) == 0: # Download button means valid product
continue
platforms = product_lxml.find_class("trove-platform-selector")
product = {'human_name': product_lxml.find_class('product-human-name')[0].text,
'machine_name': product_lxml.attrib['data-machine-name'],

for trove_id, trove_data in trove_json_obj['displayItemData'].items():
product = {'human_name': trove_data['human-name'],
'machine_name': trove_data['machine_name'],
'downloads': [],
'payee': {} # TODO: put something better here
}
for p in platforms:
for platform, platform_data in trove_data['downloads'].items():
pp = dict()
pp['platform'] = p.attrib['data-platform']
pp['download_identifier'] = p.attrib['data-url']
pp['machine_name'] = p.attrib['data-machine-name']
pp['platform'] = platform
pp['download_identifier'] = platform_data['url']['web']
pp['machine_name'] = platform_data['machine_name']
signed = hapi.get_signed_trove_url(pp['machine_name'], pp['download_identifier'])
pp['download_struct'] = [{
'url': {
'web': signed.get('signed_url', None),
'bittorrent': signed.get('signed_torrent_url', None)
}
},
'file_size': platform_data.get('file_size'),
'human_size': platform_data.get('size'),
'md5': platform_data.get('md5'),
'sha1': platform_data.get('sha1')
}]
pp['options_dict'] = None # TODO: What is this?
product['downloads'].append(pp)
Expand Down
16 changes: 5 additions & 11 deletions test/fake_library/fake_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ class FakeLibrary:
gamekeys_list = []
local_path = ""

def __init__(self, hapi, unlock_trove=True):
def __init__(self, hapi):
self.local_path = path.dirname(__file__)
self.update_gamekeys(hapi)
self.prepare_fake_answer_list_gamekeys(hapi)
self.prepare_fake_answers_keys(hapi)
self.prepare_fake_answer_trove(hapi, unlock_trove)
self.prepare_fake_answer_trove(hapi)

def update_gamekeys(self, hapi):
self.gamekeys_list = []
for filename in iglob(path.join(self.local_path, "*.key")):
self.gamekeys_list.append(path.basename(filename)[0:-4])
self.gamekeys_list.append(hapi.TROVE_GAMEKEY)

def prepare_fake_answer_trove(self, hapi, unlock_trove):
def prepare_fake_answer_trove(self, hapi):
httpretty.register_uri(
httpretty.GET,
hapi.TROVE_PAGE_URL,
self.get_trove_answer(unlock_trove)
self.readfile("trove.html")
)
httpretty.register_uri(
httpretty.POST,
Expand All @@ -49,12 +49,6 @@ def prepare_fake_answers_keys(self, hapi):
def get_answer_for(self, key):
return self.readfile(key + ".key")

def get_trove_answer(self, unlock_trove):
if unlock_trove:
return self.readfile("trove_OK.html")
else:
return self.readfile("trove_KO.html")

def prepare_fake_answer_list_gamekeys(self, hapi):
string = "[\n"
for key in self.gamekeys_list[:-1]: # Skip the trove key, as it is not reported by the API
Expand All @@ -74,4 +68,4 @@ def readfile(self, relative_path):
file = open(abs_path, "r")
text = file.read()
file.close()
return text
return text
18 changes: 17 additions & 1 deletion test/fake_library/trove_OK.html → test/fake_library/trove.html

Large diffs are not rendered by default.

Loading