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
#!/usr/bin/env python3 | |
from xfinity_usage.xfinity_usage import XfinityUsage | |
import datetime | |
import json | |
import os | |
results = XfinityUsage( | |
os.environ['XFINITY_USER'], | |
os.environ['XFINITY_PASSWORD'], | |
browser_name='chrome-headless' | |
).run() | |
raw = results['raw'] | |
courtesyUsed = raw['courtesyUsed'] | |
courtesyRemaining = raw['courtesyRemaining'] | |
courtesyAllowed = raw['courtesyAllowed'] | |
used = results['used'] | |
total = results['total'] | |
units = results['units'] | |
today = datetime.date.today() | |
nextMonth = datetime.date( | |
today.year + int(today.month == 12), | |
today.month % 12 + 1, | |
1) | |
daysRemaining = (nextMonth - today).days | |
# Be conservative, Comcast says it can take 24 hours for usage be tallied | |
extrapolatedTotal = used + daysRemaining * (used / (today.day - 0.9)) | |
print('{} of {} {} used this month'.format(used, total, units)) | |
print('{} days remaining'.format(daysRemaining)) | |
print('{:.1f} {} predicted usage'.format(extrapolatedTotal, units)) | |
if extrapolatedTotal > total: | |
# Haven't figured out how to get emoji to render in PuTTY | |
print("You're not on track :(") # \u2639") | |
print('{} of {} courtesy months remaining'.format(courtesyRemaining, courtesyAllowed)) | |
else: | |
print("You're on track!") # \U0001F44D") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment