Created
April 6, 2012 11:44
-
-
Save dannymcc/2319106 to your computer and use it in GitHub Desktop.
events
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
| desc "Import access control logs" | |
| task :fetch_accesscontrol => :environment do | |
| # Logs into website and retrieved list of events. | |
| require 'rubygems' | |
| require 'mechanize' | |
| require 'logger' | |
| # Create a new mechanize object | |
| agent = Mechanize.new | |
| # Load the hydrogen website | |
| page = agent.get("http://website.co.uk/Data.html") | |
| # Add each row to a new event record | |
| rows = page.root.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "b", " " ))]//td | //*[contains(concat( " ", @class, " " ), concat( " ", "a", " " ))]//td') | |
| details = rows.collect do |row| | |
| detail = {} | |
| [ | |
| [:name, '//*[contains(concat( " ", @class, " " ), concat( " ", "b", " " ))]//td[(((count(preceding-sibling::*) + 1) = 1) and parent::*)] | //*[contains(concat( " ", @class, " " ), concat( " ", "a", " " ))]//td[(((count(preceding-sibling::*) + 1) = 1) and parent::*)]'], | |
| ].collect do |name, xpath| | |
| detail[name] = row.at_xpath(xpath).to_s[16..-6] | |
| end | |
| detail | |
| end | |
| pp details | |
| #Event.create(:name => detail.name) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment