Package: xfinity-usage
Python/selenium script to get Xfinity bandwidth usage from Xfinity MyAccount website. Has an easily-usable
command line entrypoint as well as a usable Python API, and an entrypoint to send usage to Graphite.This is a little Python script I whipped up that theselenium-pythonpackage to log in to your Xfinity account and screen-scrape the data usage. By default the usage is just printed
to STDOUT. You can also use theXfinityUsageclass from other applications or scripts; see the
docstrings on the__init__andrunmethods for information. There are also options to send the data
to a Graphite server.For the changelog, seeCHANGES.rst in the GitHub project.Development Discontinued - Maintainer WantedAs of September 2018, AT&T Fiber has become available in my area and I’ve switched to that because of the much better pricing (I’m getting 300Mbpssymmetricalfor the same monthly price as Xfinity 100/10). As such, I won’t be able to continue maintaining this project without an Xfinity account. If anyone would like to take over maintenance, please open an Issue on GitHub and I’ll contact you.RequirementsPython (tested with 2.7; should work with 3.3+ as well)seleniumPython packageOne of the supported browsers:A recent version of PhantomJS installed on your computer; this should be 2.0+, and the script is tested with 2.1.1.Google Chrome or Chromium andchromedriverFirefox andGeckodriverInstallationpip install xfinity-usageUsageCommand LineExport your Xfinity username as theXFINITY_USERenvironment
variable, your password as theXFINITY_PASSWORDenvironment
variable, and run thexfinity-usageentrypoint. Seexfinity-usage-hand the
top-level docstring in the script for more information.I’d highly recommend not leaving your username and password hard-coded
anywhere on your system, but the methods for securing credentials are
varied enough that the choice is yours.Note that this screen-scrapes their site; it’s likely to break with a
redesign.Python APISee the source of thexfinity_usage.pyscript, specifically the__init__andrunmethods of theXfinityUsageclass. As a simple example:>>>importos>>>fromxfinity_usage.xfinity_usageimportXfinityUsage>>>u=XfinityUsage(os.environ['XFINITY_USER'],os.environ['XFINITY_PASSWORD'],browser_name='chrome-headless')>>>u.run(){
    "data_timestamp": 1523913455,
    "units": "GB",
    "used": 224.0,
    "total": 1024.0,
    "raw": {
        "courtesyUsed": 0,
        "courtesyRemaining": 2,
        "courtesyAllowed": 2,
        "inPaidOverage": false,
        "usageMonths": [
            {
                "policyName": "1 Terabyte Data Plan",
                "startDate": "10/01/2017",
                "endDate": "10/31/2017",
                "homeUsage": 408.0,
                "allowableUsage": 1024.0,
                "unitOfMeasure": "GB",
                "devices": [
                    {
                        "id": "AB:CD:EF:01:23:45",
                        "usage": 301.0
                    },
                    {
                        "id": "12:34:56:78:90:AB",
                        "usage": 107.0
                    }
                ],
                "additionalBlocksUsed": 0.0,
                "additionalCostPerBlock": 10.0,
                "additionalUnitsPerBlock": 50.0,
                "additionalIncluded": 0.0,
                "additionalUsed": 0.0,
                "additionalPercentUsed": 0.0,
                "additionalRemaining": 0.0,
                "billableOverage": 0.0,
                "overageCharges": 0.0,
                "overageUsed": 0.0,
                "currentCreditAmount": 0,
                "maxCreditAmount": 0,
                "policy": "limited"
            },
            # 5 additional months removed for brevity
            {
                "policyName": "1 Terabyte Data Plan",
                "startDate": "04/01/2018",
                "endDate": "04/30/2018",
                "homeUsage": 224.0,
                "allowableUsage": 1024.0,
                "unitOfMeasure": "GB",
                "devices": [
                    {
                        "id": "12:34:56:78:90:AB",
                        "usage": 224.0
                    }
                ],
                "additionalBlocksUsed": 0.0,
                "additionalCostPerBlock": 10.0,
                "additionalUnitsPerBlock": 50.0,
                "additionalIncluded": 0.0,
                "additionalUsed": 0.0,
                "additionalPercentUsed": 0.0,
                "additionalRemaining": 0.0,
                "billableOverage": 0.0,
                "overageCharges": 0.0,
                "overageUsed": 0.0,
                "currentCreditAmount": 0,
                "maxCreditAmount": 0,
                "policy": "limited"
            }
        ]
    }
}Note About ReliabilityIn short: xfinity’s site isn’t terribly reliable. Personally, I run this
script twice an hour via cron, so 48 times a day, every day. I usually
see 1-4 failures a day of all different failure modes - elements missing
from the page, connection resets, blank pages, server-side error
messages, etc. Keep that in mind. My code could probably do more in
terms of error handling and retries, but it’s notthatimportant to
me.RationaleComcast recently started rolling out a 1TB/month bandwidth cap in my
area. I’ve gone over my two “courtesy” months, and the overage fees are
pretty insane. I work from home, and sometimes that uses a lot of
bandwidth. I want to know when I’m getting close to my limit; this month
I’m apparently at 75% and only half way through the month, and I havenoidea how that happened.It’s entirely abusive and invasive that Comcast isinjecting bandwidth
warnings into my web
traffic,
but that’s also a pretty awful way of attempting to tell a human
something - especially given how much automated traffic my computer
generates. Moreover,Xfinity’s site has aUsage Meter(which is the source of this data), but it only shows a progress bar for
the month - no way to find out usage by day or hour to try and figure
out what the cause actually was. Also, even if I visit the usage meter
from my own computeron Xfinity’s network, using the IP address which
Xfinity assigned to me (and is tracking usage for), I still need to log
in to my account to view the usage. That’s a complete pain and seems to
serve only to prevent customers from keeping track of their usage, not
to metion preventing guests or friends from checking usage. Hell,
Xfinity used to have adesktop app to track
usagebut it’s been shut down, and a
handyscript that used the same API as the desktop
appno longer works as a
result. With all of this put together, I’d say Comcast is going to great
lengths to maximize overage fees and minimize customers’ insight into
their usage.In short, I want to be notified of my usage on a regular basis (I get
daily emails with the results of this script), and I also want to be
able to see historical trends (I push the output to Graphite).DisclaimerI have no idea what Xfinity’s terms of use for their account management website
are, or if they claim to have an issue with automating access. They used to have
a desktop app to check usage, backed by an API (seehttps://github.com/WTFox/comcastUsage), but that’s been discontinued. The fact
that they force me to login with my account credentials WHEN CONNECTING FROMTHEIRNETWORK, USING THE IP ADDRESSTHEYISSUED TO MY ACCOUNT just to check
my usage, pretty clearly shows me that Comcast cares a lot more about extracting
the maximum overage fees from their customers than the “quality of service” that
they claim these bandwidth limits exist for. So… use this at your own risk,
but it seems pretty clear (i.e. discontinuing their “bandwidth meter” desktop
app) that Comcast wants to prevent users from having a clear idea of their
supposed bandwidth usage.LicenseThis package is licensed under theGNU AGPLv3.ContributingFor information on contributing, see.github/CONTRIBUTING.md.