MestreLion / humblebundle

API for managing Humble Bundle games library
GNU General Public License v3.0
211 stars 38 forks source link

Update gamekeys regex to handle new JSON key list #51

Closed thecjharries closed 4 years ago

thecjharries commented 5 years ago

Overview

From some quick investigation, it looks like gamekeys is in a script tag now that looks like this:

<script id="user-home-json-data" type="application/json">
  {
    "activePlatform": "windows",
    "gamekeys":  ["somekeys"],
    "hasAdmin": false
  }
</script>

I updated the regex to handle this while also preserving the old format (Is that necessary? If not I can update the PR). I did some local testing and was able to make example.py work with this change. This should fix #50.

Testing

Honestly there's probably a simpler way to test this but I haven't written much code in a month and this was the faster way to get the PR out.

$ mkdir test-or-whatever
$ cd test-or-whatever

example.py

Create this file, filling in the necessary values:

from __future__ import print_function
import humblebundle

hb = humblebundle.HumbleBundle(
    'your username',
    'your password',
)

hb.update()
print(hb.games)

build.sh

This creates (and runs) the necessary files.

#/bin/bash

rm -rf ./Pipfile*
pipenv --python=2
pipenv install -e 'git+https://github.com/thecjharries/humblebundle.git#egg=humblebundle'
sed -i 's@^humble.*@humblebundle = {git = "https://github.com/thecjharries/humblebundle.git", editable = true, ref = "fix-gamekeys-regex"}@' Pipfile
pipenv install
echo '

[scripts]
example = "python example.py"' >> Pipfile
pipenv run example

Note that you might have to add auth and/or code to example.py to make things work. You can just run this instead of the entire script after doing that:

$ pipenv run example
ryokimball commented 5 years ago

I saw the GameKeys error but before I saw this pull request I tried to just delete my user data in ~/.config/humblebundle/ and I seem to have broken it even more. My guess is that the authentication parts continue to work if an old cookie is still valid, but if you have to reauth then it fails due to changes in the Humble Bundle pages. It's only a guess though since I haven't found time to dig any further.

orivej commented 4 years ago

@MestreLion, could you merge this please?

if you have to reauth then it fails due to changes in the Humble Bundle pages

This is #46, -A still works.