Created
December 20, 2012 22:13
-
-
Save moonhouse/4349029 to your computer and use it in GitHub Desktop.
Skapa RSS för dagens diarium från en av länsstyrelserna
This file contains 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
# encoding: UTF-8 | |
require 'mechanize' | |
require 'builder' | |
@agent = Mechanize.new | |
def get_list(diary_id) | |
page = @agent.get("http://diarium.lansstyrelsen.se/default.aspx") | |
form = page.form('aspnetForm') | |
form['__EVENTTARGET'] = '_ctl0$SearchPlaceHolder$CaseSearch$btnCurrentDay' | |
form['__EVENTARGUMENT'] = '' | |
form['_ctl0:SearchPlaceHolder:CaseSearch:ddDiaryID'] = diary_id.to_s | |
form['_ctl0:SearchPlaceHolder:CaseSearch:txtHiddenDiaryID'] = diary_id.to_s | |
form.submit | |
end | |
diarium = get_list 11 | |
builder = Builder::XmlMarkup.new | |
builder.instruct! | |
builder.rss :version => "2.0", "xmlns:content" => "http://purl.org/rss/1.0/modules/content/", | |
"xmlns:dc"=>"http://purl.org/dc/elements/1.1/", | |
"xmlns:media"=>"http://search.yahoo.com/mrss/", | |
"xmlns:atom"=>"http://www.w3.org/2005/Atom", | |
"xmlns:georss"=>"http://www.georss.org/georss" do | |
builder.channel do | |
builder.title 'Diarium' | |
builder.link 'http://diarium.lansstyrelsen.se/' | |
builder.description 'Länsstyrelsernas diarier' | |
builder.language 'sv-se' | |
diarium.parser.xpath('//table[@id="_ctl0_SearchPlaceHolder_caseGridView"]//tr[position() > 1]').each do |row| | |
builder.item do | |
link = 'http://diarium.lansstyrelsen.se/Case/' + row.children.first.xpath('a/@href').text | |
(diarienummer, status, in_upp_datum, arenderubrik, avsandare_mottagare, postort, | |
kommun, tillkomst, beslutsdatum, organisationsenhet) = row.children.map { |col| col.text.strip } | |
builder.category organisationsenhet | |
builder.title arenderubrik | |
builder.link link | |
builder.description do | |
builder.cdata!(avsandare_mottagare) | |
end | |
end | |
end | |
end | |
end | |
puts builder.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment