Skip to content

Instantly share code, notes, and snippets.

@johnschult
Created May 18, 2009 18:21
Show Gist options
  • Save johnschult/113654 to your computer and use it in GitHub Desktop.
Save johnschult/113654 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'atom/pub'
require 'htmlentities'
ENV['TZ'] = 'US/Eastern'
BASE_URL = "http://investorshub.advfn.com/boards/"
FORUM_URL = BASE_URL + "board.aspx?board_id=2276"
DESTINATION = "/tmp/ihub.atom"
CODER = HTMLEntities.new
feed = Atom::Feed.new do |f|
f.title = "Investor's Hub - NEOM"
f.id = "http://flairly.com/"
f.links << Atom::Link.new(:href => "http://flairly.com/ihub.atom", :rel => 'self')
Hpricot(open(FORUM_URL)).search("//table[@id='ctl00_CP1_gv']/tr").each do |row|
unless row[:style] == 'background-color:PaleGoldenrod;'
if link = (row/"td:nth(1)/a").first
f.entries << Atom::Entry.new do |e|
e.title = "#{CODER.decode((row/"td:nth(1)/a").inner_text)} ...".capitalize
e.links << Atom::Link.new(:href => "#{BASE_URL}#{link[:href]}", :rel => :alternate)
e.updated = Time.parse((row/"td:nth(3)").inner_text)
e.id = "tag:flairly.com,#{e.updated.strftime('%Y-%m-%d')}:/post/#{link[:href].match(/.*=(\d+)/)[1]}"
author = (row/"td:nth(2)/a").inner_text
e.authors << Atom::Person.new(:name => author)
message = Hpricot(open("#{BASE_URL}#{link[:href]}"))
content = message.at("//span[@id='intelliTXT']").inner_html
if replied_to = message.at("//a[@id='ctl00_CP1_mh1_hlReplyTo']")
replied_to = replied_to.inner_text
content = "<span style='font-size:small;color:gray;font-weight:bold;'>#{author} said to #{replied_to.strip}:</span><br/>" + content
end
e.content = Atom::Content::Html.new(content)
end
end
end
end
f.updated = f.entries[0].updated
end
File.open(DESTINATION,"w") do |f|
f.write(feed.to_xml)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment