commit ee2e9575d7ba906230d6f493d154ea7057e27497 Author: Andrew Tomaka Date: Wed May 31 00:22:44 2017 -0400 Initial commit diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..82c7a61 --- /dev/null +++ b/.env.sample @@ -0,0 +1,2 @@ +COMCAST_USERNAME= +COMCAST_PASSWORD= diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..0cd1438 --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +gem "addressable" +gem "dotenv" +gem "json" +gem "mechanize" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..e881643 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,46 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.5.1) + public_suffix (~> 2.0, >= 2.0.2) + domain_name (0.5.20170404) + unf (>= 0.0.5, < 1.0.0) + dotenv (2.2.1) + http-cookie (1.0.3) + domain_name (~> 0.5) + json (2.1.0) + mechanize (2.7.5) + domain_name (~> 0.5, >= 0.5.1) + http-cookie (~> 1.0) + mime-types (>= 1.17.2) + net-http-digest_auth (~> 1.1, >= 1.1.1) + net-http-persistent (~> 2.5, >= 2.5.2) + nokogiri (~> 1.6) + ntlm-http (~> 0.1, >= 0.1.1) + webrobots (>= 0.0.9, < 0.2) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + net-http-digest_auth (1.4.1) + net-http-persistent (2.9.4) + nokogiri (1.7.2) + mini_portile2 (~> 2.1.0) + ntlm-http (0.1.1) + public_suffix (2.0.5) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.4) + webrobots (0.1.2) + +PLATFORMS + ruby + +DEPENDENCIES + addressable + dotenv + json + mechanize + +BUNDLED WITH + 1.14.4 diff --git a/comcast-bandwidth.rb b/comcast-bandwidth.rb new file mode 100755 index 0000000..1edfb30 --- /dev/null +++ b/comcast-bandwidth.rb @@ -0,0 +1,52 @@ +#!/usr/bin/ruby + +require "addressable/uri" +require "dotenv" +require "json" +require "mechanize" + +Dotenv.load + +agent = Mechanize.new + +def continue_uri + Addressable::URI.new( + scheme: "https", + host: "login.comcast.net", + path: "/oauth/authorize", + query_values: { + redirect_uri: "https://customer.xfinity.com/oauth/callback", + client_id: "my-account-web", + state: "#/devices", + response_type: "code", + response: 1, + } + ) +end + +def login_uri + Addressable::URI.new( + scheme: "https", + host: "login.comcast.net", + path: "/login", + query_values: { + s: "oauth", + continue: continue_uri.to_s, + client_id: "my-account-web", + }, + ) +end + +page = agent.get(login_uri) +login_form = page.form("signin") +login_form.user = ENV["COMCAST_USERNAME"] +login_form.passwd = ENV["COMCAST_PASSWORD"] +agent.submit(login_form) + +page = agent.get("https://customer.xfinity.com/apis/services/internet/usage") +usage = JSON.parse(page.body) + +home = usage["usageMonths"].last["homeUsage"] +allowable = usage["usageMonths"].last["allowableUsage"] + +puts "#{home} of #{allowable} used"