commit 11b6b4f11039f0df3eb7ceb253fe686aeea6ffbc Author: Andrew Tomaka Date: Tue Nov 8 22:40:43 2016 -0500 Initial commit diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..c3da3ff --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'nokogiri' +gem 'twilio-ruby', '~> 4.11.1' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..f2f6a15 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,23 @@ +GEM + remote: https://rubygems.org/ + specs: + builder (3.2.2) + jwt (1.5.6) + mini_portile2 (2.1.0) + multi_json (1.12.1) + nokogiri (1.6.8.1) + mini_portile2 (~> 2.1.0) + twilio-ruby (4.11.1) + builder (>= 2.1.2) + jwt (~> 1.0) + multi_json (>= 1.3.0) + +PLATFORMS + ruby + +DEPENDENCIES + nokogiri + twilio-ruby (~> 4.11.1) + +BUNDLED WITH + 1.13.5 diff --git a/README.md b/README.md new file mode 100644 index 0000000..17cc804 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# Ruby User Group, 08 Nov 2016 + +Text alerting on a website content change + +* web request + +require 'net/http' +uri = URI('https://github.com/chrisvfritz') +content = Net::HTTP.get(uri) + +* parse content + +require 'nokogiri' +parsed = Nokogiri::HTML(content) +chris\_face = parse.css('.avatar').attr('src').value + +* ??? (process) + +* send text + +require 'twilio-ruby' +client = Twilio::REST::Client.new(account\_sid, auth\_token) +client.messages.create( + from: from\_number, + to: notification\_number, + body: 'Repos changed' +) diff --git a/chris-stalker.rb b/chris-stalker.rb new file mode 100644 index 0000000..3962a26 --- /dev/null +++ b/chris-stalker.rb @@ -0,0 +1,46 @@ +#!/bin/ruby + +require 'net/http' +require 'nokogiri' +require 'twilio-ruby' + +WAIT_TIME = 15 +account_sid = 'TWILIO_ACCOUNT' +auth_token = 'TWILIO_TOKEN' + +from_number = '+15555555555' +notification_number = '+15555555555' + +client = Twilio::REST::Client.new(account_sid, auth_token) + +last_time = 0 +previous_repos = [] +while true do + # web request + uri = URI('https://github.com/chrisvfritz') + content = Net::HTTP.get(uri) + + # parse content + parsed = Nokogiri::HTML(content) + repos = parsed.css('.pinned-repo-item-content .d-block a').map do |r| + r.text.strip + end + + # ??? (process) + if repos - previous_repos != [] + time = Time.now.to_i + if time_past(time, last_time) + # send text + client.messages.create( + from: from_number, + to: notification_number, + body: 'Repos changed' + ) + last_time = time + end + + previous_repos = repos + end + + sleep(2) +end