Guest User

Untitled

a guest
Jul 18th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #!/usr/bin/env groovy
  2.  
  3. @Grab(group='commons-lang', module='commons-lang', version='2.5')
  4. @Grab(group='net.sf.ezmorph', module='ezmorph', version='1.0.6')
  5. @Grab(group='commons-collections', module='commons-collections', version='3.2.1')
  6. @Grab(group='commons-beanutils', module='commons-beanutils', version='1.8.3')
  7. @Grab('net.sf.json-lib:json-lib:2.3-jdk15')
  8. import net.sf.json.*
  9.  
  10. def cli = new CliBuilder(usage:'del2scrumptious.groovy')
  11. cli.in(args: 1, argName: 'delicous xml-file', required: true, 'File containing the xml export from Delicious')
  12. cli.out(args: 1, argName: 'output filename', required: true, 'File where the Scrumptious-style JSON will be saved')
  13. def options = cli.parse(args)
  14.  
  15. if(!options) {
  16. System.exit(0)
  17. }
  18.  
  19. def posts = new XmlSlurper().parse(new File(options.in))
  20.  
  21. def data = posts.post.collect { post ->
  22. [type: 'bookmark',
  23. title: post.@description.text(),
  24. url: post.@href.text(),
  25. description: post.@extended.text(),
  26. date: post.@time.text(),
  27. tags: post.@tag.text().split(" "),
  28. imported: true]
  29. }
  30.  
  31. def json = JSONSerializer.toJSON([docs: data])
  32.  
  33. new File(options.out).withWriter('UTF-8') {
  34. it << json.toString()
  35. }
Add Comment
Please, Sign In to add comment