Skip to content

Instantly share code, notes, and snippets.

@jmtame
Created September 10, 2012 09:08
Show Gist options
  • Save jmtame/3689796 to your computer and use it in GitHub Desktop.
Save jmtame/3689796 to your computer and use it in GitHub Desktop.
office_hours.rb
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'mechanize'
require '~/Desktop/auth.rb'
agent = Mechanize.new
page = agent.get("http://news.ycombinator.com/newslogin?whence=news")
# Create the session
form = agent.page.forms.first
form.u = 'jmtame'
form.p = $pass
logged_in_page = form.submit form.buttons.first
# Parse out the date, time, and host
page = agent.get("http://news.ycombinator.com/booker")
page.search("td.admin tr td").each do |td|
if td.text =~ /\d+:\d.*to.*\d:\d+/i # "12:00 pm to 12:20 pm"
date = td.text.scan(/\d{1,}.*\d{4}/i).first # eg "10 September 2012"
time = td.text.scan(/\d+:\d+.* to \d+:\d+.{3}/i).first # "12:00 pm to 12:20 pm"
host = td.text.scan(/with\s\w{1,50}/i).first.split(" ")[1] # "harj"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment