Skip to content

Instantly share code, notes, and snippets.

@dysinger
Created March 14, 2009 00:22
Show Gist options
  • Save dysinger/78850 to your computer and use it in GitHub Desktop.
Save dysinger/78850 to your computer and use it in GitHub Desktop.
Unfuddle Screen Scrape of CSV Tickets -> iCal
%W(mechanize icalendar fastercsv date).each {|l| require l}
namespace(:unfuddle) do
desc("unfuddled ical")
task(:ical, [:user, :pass]) do |t,a|
agent = WWW::Mechanize.new
agent.get("https://sonian.unfuddle.com") do |login|
home = login.form_with(:action => '/session') do |form|
form.authenticity_token ="19bc194e909975bf8cf502810b51e872bf7df728"
form.username = a[:user]
form.password = a[:pass]
end.click_button
projects = agent.click(home.link_with(:text => 'Projects'))
sonian = agent.click(projects.link_with(:text => 'Sonian'))
tickets = agent.click(sonian.link_with(:text => 'Tickets'))
report = agent.click(tickets.link_with(:text => 'All Tickets'))
agent.click(report.links.find { |l| l.href =~ /\.csv$/ }).
save_as("/tmp/sonian.csv")
end
cal = Icalendar::Calendar.new
csv = FasterCSV.foreach("/tmp/sonian.csv",
{:headers => true, :header_converters => :symbol}) do |row|
cal.todo do |todo|
todo.uid = "#{row.field(:project_id)}-#{row.field(:id)}-#{row.field(:number)}"
todo.summary = "\##{row.field(:number)} #{row.field(:summary)}" <<
" [Sonian #{row.field(:project_title)}]"
todo.description =
"url: https://sonian.unfuddle.com/projects/#{row.field(:project_id)}" <<
"/tickets/by_number/#{row.field(:number)}\n" <<
"milestone: #{row.field(:milestone_title)}\n" <<
"assigned: #{row.field(:assignee_name)}\n" <<
"\n" <<
row.field(:description)
todo.priority = (((6 - row.field(:priority).to_i) * 2) - 1).to_s
todo.due = Date.parse(row.field(:due_on)) unless "" == row.field(:due_on).to_s
todo.completed =
Date.parse(row.field(:updated_at)) if row.field(:status) == "closed"
end
end
File.open("/tmp/sonian.ics", "w") { |f| f.write(cal.to_ical) }
`open /tmp/sonian.ics`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment