1
0
Fork 0

Initial commit

This commit is contained in:
Andrew Tomaka 2017-05-31 00:22:44 -04:00
commit ee2e9575d7
5 changed files with 107 additions and 0 deletions

2
.env.sample Normal file
View File

@ -0,0 +1,2 @@
COMCAST_USERNAME=
COMCAST_PASSWORD=

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env

6
Gemfile Normal file
View File

@ -0,0 +1,6 @@
source "https://rubygems.org"
gem "addressable"
gem "dotenv"
gem "json"
gem "mechanize"

46
Gemfile.lock Normal file
View File

@ -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

52
comcast-bandwidth.rb Executable file
View File

@ -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"