Yes please, that sounds very useful.
It's a bit raw, but it might be useful. It uses gdata-ruby which I
don't know if it still exists, but I guess something similar exists (a
gem search of gdata shows plenty of options). It accepts an argument
to choose between a couple of spreadsheets, and has a mapping to a
wiki page in which to post. It replaces the table in that page with
the new version. It also uses some values in some cells to choose a
background color for those rows. It reads a YAML file with the google
authentication and the wiki authentication data. It also goes through
some hoops to log into my company's intranet tool and then into the
wiki inside:
require 'net/http'
require 'net/https'
require 'uri'
require 'hpricot'
require 'date'
require 'faster_csv'
require 'mechanize'
# Usage:
# gcsv2wikitable.rb catalogue|tools
#
mapping =3D {"catalogue" =3D> {:spreadsheet =3D> "CatalogueManagerPhase2",
:worksheet =3D> "Roadmap", :wiki_page =3D>
"Region3:UK/Catalogue_Manager/Roadmap"},
"tools" =3D> {:spreadsheet =3D> "ToolsRoadmap", :worksheet =3D>
"List", :wiki_page =3D> "Region3:UK/Tools_Roadmap"}}
target =3D mapping[ARGV[0]]
unless target
puts "#{ARGV[0]} doesn't represent a valid target"
exit
end
spreadsheet =3D ""
require 'spreadsheetservice'
puts "Downloading spreadsheet"
service =3D GData::Spreadsheet::SpreadsheetService.new
account =3D File.open("googlecsv2wiki.config") {|file| YAML::load(file)}
service.authenticate(account["Email"], account["Passwd"])
sp =3D service.get_spreadsheets.find {|s| s.title =3D=3D target[:spreadshee=
t]}
worksheet =3D sp.get_worksheets.find {|w| w.title =3D=3D target[:worksheet]=
}
rows =3D worksheet.get_row_list(true)
header =3D rows.shift
spreadsheet << header.join(",") << "\n"
rows.each {|row| spreadsheet << '"' << row.field_values.join('","') << "\"\=
n"}
puts "Spreadsheet correctly downloaded"
puts spreadsheet
puts "--------------------------------"
# Publish the csv to the wiki
wiki_table =3D<<END
{| border=3D"1"
END
def to_wiki_header(line)
fields =3D line.map {|field| "!#{field[1]}"}.join("\n")
"|- style=3D\"background:#efefef;\" align=3D\"center\"\n#{fields}"
end
def to_wiki_row(line)
fields =3D line.map {|field| "| #{field[1]}"}.join("\n")
row_prefix =3D "|- "
case line.entries[-1][1]
when "Production"
row_prefix << "style=3D\"background:#00ff00;\""
when "In progress"
row_prefix << "style=3D\"background:yellow;\""
end
row_prefix + "\n" + fields
end
FasterCSV.parse(spreadsheet, {:headers =3D> :first_row, :return_headers
=3D> true}) do |line|
if line.header_row?
wiki_table << to_wiki_header(line)
else
wiki_table << to_wiki_row(line)
end
wiki_table << "\n"
end
wiki_table << "|}"
agent =3D WWW::Mechanize.new
agent.user_agent_alias=3D'Linux Mozilla'
# get login page
page =3D agent.get("
http://mycompany's intranet tool")
# do login
form =3D page.form("login_form")
form.username =3D account["WikiUser"]
form.password =3D account["WikiPassword"]
page =3D agent.submit(form, form.buttons.first)
# go to B!Wiki
page =3D agent.click(page.links.text("B!Wiki"))
# Submit a form to login in the wiki
page =3D agent.submit(page.form("userlogin"))
# find the page and edit it
page =3D agent.click(page.links.text("Welcome"))
page =3D agent.get("
http://mycompany's intranet tool/wiki/index.php/" +
target[:wiki_page])
page =3D agent.click page.links.text("Edit")
# insert the new value for the table
form =3D page.form("editform")
form.wpTextbox1.gsub!(/\{\|.*?\|\}/m, wiki_table)
# submit
agent.submit(form, form.buttons.first)
puts "Posted"
Hope this helps,
Jesus.