the great ruby editor and ide roundup

J

Jesús Gabriel y Galán

Also, mirroring to a wiki would be nice idea. Google docs is still the
best way I've seen to actually *edit* it, though - entering tabular
data on wikipedia for instance is extremely clunky. It should be
possible to write a script to extract a nightly csv dump of the
document and back it up somewhere, then use pandoc to convert that to
the appropriate wiki format and keep that updated. I'll look into it.

I have a script that reads a Google Docs excel file and imports it
into a Mediawiki page in tabular format using mechanize.
If there's interest I can share it.

Jesus.
 
M

Martin DeMello

2010/8/31 Jes=FAs Gabriel y Gal=E1n said:
I have a script that reads a Google Docs excel file and imports it
into a Mediawiki page in tabular format using mechanize.
If there's interest I can share it.

Yes please, that sounds very useful.

martin
 
J

Jesús Gabriel y Galán

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.
 
M

Martin DeMello

2010/8/31 Jes=FAs Gabriel y Gal=E1n said:
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:

Thanks! Will play with this when I get home tonight.

martin
 
M

Markus Fischer

Hi,

https://spreadsheets.google.com/ccc?key=0Al_hzYODcgxwdG9tUFhqcVVoUDVaLTlqT2YtNjV1N0E&hl=en

Fill in the details for your favourite editor. Add it if it's missing
:) Feel free to add additional columns too.

I've added format rules to change background color based on content of
"yes" and "no" fields (light green and light red respectively). That way
I find it easier to get an overview feeling. Other values leave the
background color untouched to easier spot other values. Hope that's ok.

- Markus
 
M

Martin DeMello

Hi,



I've added format rules to change background color based on content of
"yes" and "no" fields (light green and light red respectively). That way
I find it easier to get an overview feeling. Other values leave the
background color untouched to easier spot other values. Hope that's ok.

Nice :) Didn't know google docs could do format rules.

martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top