Created
May 18, 2014 05:12
-
-
Save srgrn/ddd69e32835b9983f10f to your computer and use it in GitHub Desktop.
comparing steam games with unclaimed humble bundle keys
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
import requests | |
from bs4 import BeautifulSoup | |
import getpass | |
import steamapi # from https://github.com/smiley/steamapi | |
import sys | |
import re | |
username = raw_input('Humble Bundle Username:') | |
password = getpass.getpass('Humble Bundle Password:') | |
steamUserName = raw_input('Steam User Name:') | |
steamapi.core.APIConnection(api_key="E3B127D736CA4DA31CF91C7A5B871F9F") | |
with requests.Session() as s: | |
s.post('https://www.humblebundle.com/login',data={'username':username,'password':password}) | |
r = s.get('https://www.humblebundle.com/home') | |
allkeys = re.search(r'gamekeys:\s+\[(?:\s?(".+"),?\s?)+]',r.text) # it is stupid to continue being stuck on this | |
keys = [] | |
if allkeys is not None: | |
keys = allkeys.group(1).split(',') | |
free = [] | |
used = [] | |
for k in keys: | |
k = str(k.strip().replace('"','')) | |
r = s.get('https://www.humblebundle.com/downloads',params={'key': k }) | |
soup = BeautifulSoup(r.text) | |
#print soup | |
steam = soup.find('div',{'id':'steam-tab'}) | |
if steam is not None: | |
items = zip(steam.find_all('div',class_="redeemheading"),steam.find_all('div',class_="keyfield")) | |
for title in items: | |
if title[1].text == "Click the button to redeem on Steam": | |
free.append(title[0].text) | |
else: | |
used.append(title[0].text) | |
user = steamapi.user.SteamUser(userurl=steamUserName) | |
userGames = [g.name for g in user.games] | |
inboth = set(free) & set(userGames) | |
print inboth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment