Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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()
- }
Add Comment
Please, Sign In to add comment