My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env ruby
=begin
This script convert a xml generated with "mysql --xml" into another format
of xml, which can be used on Atom notbook impoting for Google Notebook.

Usage:
To get an input xml file, you can run command like this:
$ mysql foo --xml -e "select body as content from bar where user_id = 1" > foo.xml
(Be sure, selected column must be named as "content")

Then give it this script:
$ ruby mysql_xml2google_notebook_atom.rb < foo.xml > foo.atom
After that, you can upload the resulted atom file via Google Notebook's import interface.

KnownIssues:
* Only content of entry, not updated or any other element

ChangeLogs:
0.1 (2008-11-24)
* First release

Authoer: Hiroshi Saito <hiroshi3110@gmail.com>
=end
require "rexml/document"

# input document
input = REXML::Document.new ARGF.read

# output document
output = REXML::Document.new
output << REXML::XMLDecl.new("1.0", "utf-8")
feed = output.add_element("feed", "xmlns" => "http://www.w3.org/2005/Atom")
feed.add_element("title", "type" => "text").text = "tagnote"
# void selection
section_entry = feed.add_element("entry")
section_id = section_entry.add_element("id")
section_id.text = "2"
section_entry.add_element("category", "scheme" => "http://schemas.google.com/g/2005#kind", "term" => 'http://schemas.google.com/notebook/2008/kind#section')
section_entry.add_element("title", "type" => "text")
section_entry.add_element("content", "type" => "text")
# note entries
input.elements.each("resultset/row") do |row|
entry = feed.add_element("entry")
entry.add_element("category", "scheme" => 'http://schemas.google.com/notebook/gdata/2007/section', "term" => section_id.text, "label" => 'title')
entry.add_element("category", "scheme" => 'http://schemas.google.com/g/2005#kind', "term" => 'http://schemas.google.com/notebook/2008/kind#note')
entry.add_element("title", "type" => "text")
entry.add_element("content", "type" => "text").text = row.elements["field[@name='content']"].text
end
# get result
puts output

Change log

r3 by hiroshi3110 on Nov 23, 2008   Diff
propset svn:executable
Go to: 
Project members, sign in to write a code review

Older revisions

r2 by hiroshi3110 on Nov 23, 2008   Diff
add main script
All revisions of this file

File info

Size: 2001 bytes, 50 lines

File properties

svn:executable
*
Powered by Google Project Hosting