Skip to content

Instantly share code, notes, and snippets.

@xlson
Created December 27, 2010 12:20
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Script that transforms the Delicious backup-xml into json for import into the CouchDB application Scrumptious
#!/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()
}
@xlson
Copy link
Author

xlson commented Dec 27, 2010

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment