Created
August 10, 2019 00:24
-
-
Save jathanism/6e615ac4a14920f8df7e0e4ce640df28 to your computer and use it in GitHub Desktop.
A simple script that fetches the page for the Unicron Transformer on Hasbro Pulse and does some calculations since the UI view is done in JavaScript.
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| """ | |
| Track stats for Unicron. | |
| Requirements: | |
| - Python3 | |
| - pip install bs4 requests | |
| """ | |
| import datetime | |
| import re | |
| from bs4 import BeautifulSoup | |
| import requests | |
| url = 'https://hasbropulse.com/products/transformers-war-for-cybertron-unicron' | |
| selector = 'p.crowdfunding-bar__details.lead.left > strong' | |
| needed = 8000 | |
| expires = datetime.datetime(2019, 9, 1) | |
| today = datetime.datetime.now() | |
| tz_offset = 3 # 3 hours EST | |
| r = requests.get(url) | |
| html = r.text | |
| soup = BeautifulSoup(html, 'html.parser') | |
| # Turn '<strong>2,078</strong>' into int 2078.0 | |
| current = int(soup.select(selector)[0].string.replace(',', '')) | |
| remaining = needed - current | |
| percent = (float(current) / needed) * 100 | |
| # Date math | |
| delta = expires - today | |
| days = delta.days | |
| backers_per_day = int(remaining / days) | |
| hours_raw = (delta.seconds / 60 / 60) - tz_offset | |
| hours = int(hours_raw) | |
| minute_ratio = float('.' + str(hours_raw).split('.')[1] ) | |
| minutes = int(minute_ratio * 60) | |
| print(f'{current} Backers -> Target {needed} ({percent:0.2f}% Funded)') | |
| print(f'Funding ends in: {days} Days {hours} Hours {minutes} Minutes') | |
| print(f'Backers needed per day: {backers_per_day}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment