Created
October 24, 2020 10:43
-
-
Save graphicagenda/84031b596a877ec38565ee47e58d0128 to your computer and use it in GitHub Desktop.
Listing out Humble Bundles from the home page
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
from collections import namedtuple | |
from bs4 import BeautifulSoup as Soup | |
import requests | |
import json | |
from datetime import datetime, timedelta | |
import webbrowser | |
from collections import Counter | |
HB = 'https://www.humblebundle.com' | |
CONTENT = requests.get(HB).text | |
Bundle = namedtuple('Bundle', 'title blurb type stamp url end') # description type image link | |
''' | |
@TODO - get the time left for each bundle | |
- user option to navigate into the bundle of choice | |
- get the titles in each tier of the bundles found | |
- user option to visit any of the bundles found in the tiles | |
''' | |
def get_bundles(): | |
"""make a Soup object, parse the relevant html sections, and return a Bundle namedtuple""" | |
soup = Soup(CONTENT, 'html.parser') | |
parse = soup.find('script', {"id": "base-webpack-json-data"}).contents[0].strip() | |
data = json.loads(parse) | |
bundles = data['navbar']['productTiles'] | |
return [Bundle(bundles[i]['tile_name'], bundles[i]['short_marketing_blurb'], bundles[i]['type'], bundles[i]['tile_stamp'].replace('_stamp', ''), bundles[i]['url'], datetime.strptime(bundles[i]['end_date'], '%Y-%m-%dT%H:%M:%S')) for i in range(len(bundles))] | |
def dedupe_stamps(list_): | |
temp = [] | |
for i in list_: | |
if i.stamp not in temp: | |
temp.append(i.stamp) | |
return temp | |
the_bundles = get_bundles() | |
stamps = dedupe_stamps(the_bundles) | |
cstamp = Counter(b.stamp for b in the_bundles) | |
stamps.sort() | |
for k in stamps: | |
if k.lower() != "choice": | |
print(f"{k.title()}: {cstamp[k]}") | |
print('') | |
for i, b in zip(range(len(the_bundles)), the_bundles): | |
if b.stamp.lower() != "choice": | |
print(f"{i:>2}. {b.title}") | |
print(''.ljust(5), f">>>> {b.stamp.title()} {b.type.title()} | Ends in {(b.end - datetime.today()).days} days") | |
print(''.ljust(5), f"https://www.humblebundle.com/{b.url}") | |
print('') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment