Skip to content

Instantly share code, notes, and snippets.

@ihower
Created April 12, 2011 12:47
Show Gist options
  • Save ihower/915440 to your computer and use it in GitHub Desktop.
Save ihower/915440 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'nokogiri'
require 'fastercsv'
doc = Nokogiri::HTML( File.read("timesheet.txt") )
memo = {}
elapsed = {}
doc.css('div').each do |div|
if div.attributes["class"].value =~ /(.*)-memo$/
memo[$1] = div.content
end
end
doc.css('td').each do |td|
if td.attributes["class"].value =~ /(.*)-elapsed$/
elapsed[$1] = td.content
end
end
keys = (memo.keys + elapsed.keys).uniq
FasterCSV.open("timesheet.csv", "w") do |csv|
csv << ["memo", "elapsed"]
keys.each do |key|
csv << [ memo[key], elapsed[key] ]
end
end
<div class="a-memo"><b><big>memotext</big></b></div>
<table>
<tr>
<td class="a-elapsed">01:15:00</td>
</tr>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment