1
0
Fork 0

Initial commit

This commit is contained in:
Andrew Tomaka 2016-11-08 22:40:43 -05:00
commit 11b6b4f110
4 changed files with 100 additions and 0 deletions

4
Gemfile Normal file
View file

@ -0,0 +1,4 @@
source 'https://rubygems.org'
gem 'nokogiri'
gem 'twilio-ruby', '~> 4.11.1'

23
Gemfile.lock Normal file
View file

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

27
README.md Normal file
View file

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

46
chris-stalker.rb Normal file
View file

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