Tip: Click lines to highlight, hold ctrl/cmd to multi-select
http://codedumper.com/imupo (5-Oct @ 14:57)
Syntax Highlighted Code
- require 'net/http'
- require 'hpricot'
- require 'rss/maker'
- require 'uri'
- class EMB
- attr_writer :realm, :user, :password
- def initialize ( realm = 'chs_programming', user='zichun', password='paksux' )
- @realm, @user, @password = realm, user, password
- @cookies = []
- @cookie_string = ''
- end
- def get_cookie
- http = Net::HTTP.new('smb.chs.edu.sg', 80)
- resp,data = http.post('/cgi-bin/emb/login.pl',
- "userid=#{@user}&password=#{@password}&login=+++Login+++",
- {'referer'=>'http://smb.chs.edu.sg/emb/'+@realm+'/',
- 'user_agent'=>'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008051206 Firefox/3.0'
- })
- resp.get_fields('set-cookie').each { |x|
- @cookies << x
- @cookie_string += x.split("\; ")[0] + "\;"
- }
- @cookie_string
- end
- def get_main
- http = Net::HTTP.new('smb.chs.edu.sg', 80)
- http.get('/cgi-bin/emb/view.pl?date', {'Cookie'=>@cookie_string})
- end
- def get_msg (link)
- url = URI.parse(link)
- http = Net::HTTP.new('smb.chs.edu.sg',80)
- http.get( url.path+'?'+url.query, {'Cookie'=>@cookie_string} )
- end
- end
- emb_client = EMB.new
- emb_client.get_cookie
- res = emb_client.get_main
- version = "2.0"
- content = RSS::Maker.make(version) { |m|
- m.channel.title = "EMB CHS_PROGRAMMING"
- m.channel.link = "http://smb.chs.edu.sg/emb/chs_programming"
- m.channel.description = "Extracted messages from chs_programming EMB"
- m.items.do_sort = true
- doc = Hpricot(res.body)
- for i in 2...(doc/"form").length
- item = m.items.new_item
- x = (doc/"form")[i]
- item.title = (x/"a").text
- item.link = "http://smb.chs.edu.sg/emb/chs_programming/"
- item.date = Time.parse(((x/"font")[0]).innerHTML.strip)
- emb_body = Hpricot(emb_client.get_msg( x.at("a")['href'] ).body)
- item.description = emb_body.at("pre")
- item.author = (x/"td")[2].innerHTML.strip
- end
- }
- $stdout.write(content)
Plain Code
require 'net/http'
require 'hpricot'
require 'rss/maker'
require 'uri'
class EMB
attr_writer :realm, :user, :password
def initialize ( realm = 'chs_programming', user='zichun', password='paksux' )
@realm, @user, @password = realm, user, password
@cookies = []
@cookie_string = ''
end
def get_cookie
http = Net::HTTP.new('smb.chs.edu.sg', 80)
resp,data = http.post('/cgi-bin/emb/login.pl',
"userid=#{@user}&password=#{@password}&login=+++Login+++",
{'referer'=>'http://smb.chs.edu.sg/emb/'+@realm+'/',
'user_agent'=>'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008051206 Firefox/3.0'
})
resp.get_fields('set-cookie').each { |x|
@cookies << x
@cookie_string += x.split("\; ")[0] + "\;"
}
@cookie_string
end
def get_main
http = Net::HTTP.new('smb.chs.edu.sg', 80)
http.get('/cgi-bin/emb/view.pl?date', {'Cookie'=>@cookie_string})
end
def get_msg (link)
url = URI.parse(link)
http = Net::HTTP.new('smb.chs.edu.sg',80)
http.get( url.path+'?'+url.query, {'Cookie'=>@cookie_string} )
end
end
emb_client = EMB.new
emb_client.get_cookie
res = emb_client.get_main
version = "2.0"
content = RSS::Maker.make(version) { |m|
m.channel.title = "EMB CHS_PROGRAMMING"
m.channel.link = "http://smb.chs.edu.sg/emb/chs_programming"
m.channel.description = "Extracted messages from chs_programming EMB"
m.items.do_sort = true
doc = Hpricot(res.body)
for i in 2...(doc/"form").length
item = m.items.new_item
x = (doc/"form")[i]
item.title = (x/"a").text
item.link = "http://smb.chs.edu.sg/emb/chs_programming/"
item.date = Time.parse(((x/"font")[0]).innerHTML.strip)
emb_body = Hpricot(emb_client.get_msg( x.at("a")['href'] ).body)
item.description = emb_body.at("pre")
item.author = (x/"td")[2].innerHTML.strip
end
}
$stdout.write(content)