Skip to content

Instantly share code, notes, and snippets.

@chadaustin
Created May 4, 2018 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadaustin/d41a5833abed159390eec044839d7070 to your computer and use it in GitHub Desktop.
Save chadaustin/d41a5833abed159390eec044839d7070 to your computer and use it in GitHub Desktop.
#!/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