Created
April 3, 2012 09:42
-
-
Save emasaka/2290717 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'nokogiri' | |
| require 'open-uri' | |
| def scrape | |
| html = open('http://forkwell.com/') {|io| io.read } | |
| Nokogiri::HTML(html, 'utf-8').css('div.grid-unit').map do |sect| | |
| title = sect.css('header h1 a')[0]['alt'] | |
| items = [] | |
| sect.css('div.activities li a').each do |item| | |
| txt = item.text.chomp | |
| items << txt unless txt == 'See more' | |
| end | |
| { :title => title, :items => items } | |
| end | |
| end | |
| def check(marks) | |
| scrape.each do |sect| | |
| mark = marks[sect[:title]] | |
| marks[sect[:title]] = sect[:items][0] | |
| sect[:items].each do |item| | |
| break if item == mark | |
| yield sect[:title], item | |
| end | |
| end | |
| end | |
| def forkwellwatch(interval) | |
| marks = {} | |
| loop do | |
| ts = Time.now.strftime('%R') | |
| check(marks) do |title, item| | |
| puts "#{ts}: #{title}: #{item}" | |
| end | |
| sleep interval | |
| end | |
| end | |
| if __FILE__ == $0 | |
| forkwellwatch 60 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment