Created
December 27, 2010 12:20
-
-
Save xlson/756095 to your computer and use it in GitHub Desktop.
Script that transforms the Delicious backup-xml into json for import into the CouchDB application Scrumptious
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
@Grab(group='commons-lang', module='commons-lang', version='2.5') | |
@Grab(group='net.sf.ezmorph', module='ezmorph', version='1.0.6') | |
@Grab(group='commons-collections', module='commons-collections', version='3.2.1') | |
@Grab(group='commons-beanutils', module='commons-beanutils', version='1.8.3') | |
@Grab('net.sf.json-lib:json-lib:2.3-jdk15') | |
import net.sf.json.* | |
def cli = new CliBuilder(usage:'del2scrumptious.groovy') | |
cli.in(args: 1, argName: 'delicous xml-file', required: true, 'File containing the xml export from Delicious') | |
cli.out(args: 1, argName: 'output filename', required: true, 'File where the Scrumptious-style JSON will be saved') | |
def options = cli.parse(args) | |
if(!options) { | |
System.exit(0) | |
} | |
def posts = new XmlSlurper().parse(new File(options.in)) | |
def data = posts.post.collect { post -> | |
[type: 'bookmark', | |
title: post.@description.text(), | |
url: post.@href.text(), | |
description: post.@extended.text(), | |
date: post.@time.text(), | |
tags: post.@tag.text().split(" "), | |
imported: true] | |
} | |
def json = JSONSerializer.toJSON([docs: data]) | |
new File(options.out).withWriter('UTF-8') { | |
it << json.toString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scrumptious is an application for handling bookmarks. It's not unlike the soon to be dead Delicious and is built completely within CouchDB. More about Scrumptious here: http://blog.fupps.com/2010/05/25/truly-scrumptious-bookmarks-in-couchdb/