Last active
August 29, 2015 13:56
-
-
Save DinisCruz-Dev/9287743 to your computer and use it in GitHub Desktop.
Groovy scripts to parse Blogger export xml
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
def editor = eclipse.editors.get("blog-02-28-2014 (1).xml").getEditor(true); | |
def xmlFile = editor.getEditorInput().fileStore.toString(); | |
return xmlFile; |
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
xmlFile = "/Users/plugin/Downloads/blog-02-28-2014 (1).xml"; | |
def xml = new XmlParser().parse(xmlFile) | |
return xml.children().size(); |
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
xmlFile = "/Users/plugin/Downloads/blog-02-28-2014 (1).xml"; | |
def xml = new XmlParser().parse(xmlFile) | |
return xml.title.first() | |
return xml.entry.size() // = 1338 | |
return xml.title.size() // = 1 | |
return xml.link.size() // = 4 |
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
xmlFile = "/Users/plugin/Downloads/blog-02-28-2014 (1).xml"; | |
def xml = new XmlParser().parse(xmlFile) | |
def entry = xml.entry[10];//.first(); | |
show(entry) | |
return entry; |
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
xmlFile = "/Users/plugin/Downloads/blog-02-28-2014 (1).xml"; | |
def xml = new XmlParser().parse(xmlFile) | |
def titles = xml.entry.collect { it.title[0].value()[0] } . take (20); | |
def view = eclipse.views.create("Blogger data viewer").clear(); | |
view.add.treeViewer().add_Nodes(titles); | |
return titles; |
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
xmlFile = "/Users/plugin/Downloads/blog-02-28-2014 (1).xml"; | |
def xml = new XmlParser().parse(xmlFile) | |
def view = eclipse.views.create("Blogger data viewer").clear(); | |
def table = view.add.table(); | |
table.columns("title"); | |
for(def entry in xml.entry.take(20)) | |
{ | |
table.add_Row(entry.title[0].value()[0]); | |
} | |
return "done"; |
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
def xmlFile = "/Users/plugin/Downloads/blog-02-28-2014 (1).xml"; | |
def xml = new XmlParser().parse(xmlFile) | |
def view = eclipse.views.create("Blogger data viewer").clear(); | |
def table = view.add.table(); | |
table.columns("category", "title"); | |
for(def entry in xml.entry.drop(20).take(20)) | |
{ | |
def title = entry.title[0].value()[0]; | |
def category = entry.category[0].attributes().term; | |
table.add_Row(category,title); | |
} | |
return "done"; |
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
def xmlFile = "/Users/plugin/Downloads/blog-02-28-2014 (1).xml"; | |
def xml = new XmlParser().parse(xmlFile) | |
def categories = xml.entry.collect { it.category[0] .attributes().term }.unique(); | |
return categories; |
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
def xmlFile = "/Users/plugin/Downloads/blog-02-28-2014 (1).xml"; | |
def xml = new XmlParser().parse(xmlFile) | |
def categoryToFind = "http://schemas.google.com/blogger/2008/kind#post"; | |
def allPosts = xml.entry.findAll { it.category[0] .attributes().term == categoryToFind }; | |
return allPosts.size(); | |
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
def xmlFile = "/Users/plugin/Downloads/blog-02-28-2014 (1).xml"; | |
def xml = new XmlParser().parse(xmlFile) | |
def categoryToFind = "http://schemas.google.com/blogger/2008/kind#post"; | |
def allPosts = xml.entry.findAll { it.category[0] .attributes().term == categoryToFind }; | |
def view = eclipse.views.create("Blogger data viewer").clear(); | |
def table = view.add.table(); | |
table.columns("title", "publish date", "categories"); | |
for(def entry in allPosts.take(20)) | |
{ | |
def title = entry.title[0].value()[0]; | |
def publishDate = entry.published[0].value(); | |
def categories = entry.category.collect { it.attributes().term}.drop(1).sort() | |
table.add_Row(title, publishDate, categories); | |
} | |
return "done"; |
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
def xmlFile = "/Users/plugin/Downloads/blog-03-09-2014.xml"; | |
def xmlParser = new XmlParser(); | |
def xml = xmlParser.parse(xmlFile) | |
def categoryToFind = "http://schemas.google.com/blogger/2008/kind#post"; | |
def allPosts = xml.entry.findAll { it.category[0] .attributes().term == categoryToFind && | |
it["app:control"].size() > 0}; | |
// the app:control will contain this entry (when a draf) | |
/* | |
<app:control xmlns:app="http://purl.org/atom/app#"> | |
<app:draft> | |
yes | |
</app:draft> | |
</app:control> | |
*/ | |
return allPosts.size() | |
//this is one way to create an XML file | |
def _entry =allPosts.find { it.title[0].value()[0] == 'Using Firebase Token Generator' } | |
def writer = new StringWriter() | |
new XmlNodePrinter(new PrintWriter(writer)).print(_entry.first()) | |
def result = writer.toString() | |
return result; |
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
def xmlFile = "/Users/plugin/Downloads/blog-03-09-2014.xml"; | |
def xmlParser = new XmlParser(); | |
def xml = xmlParser.parse(xmlFile) | |
def categoryToFind = "http://schemas.google.com/blogger/2008/kind#post"; | |
def allPosts = xml.entry.findAll { it.category[0] .attributes().term == categoryToFind && | |
it["app:control"].size() == 0}; | |
def view = eclipse.views.create("Blogger data viewer").clear(); | |
def table = view.add.table(); | |
def browser = view.add.browser(); | |
def _eclipse = eclipse; | |
table.set.event.onSelection(new Runnable() { public void run() | |
{ | |
try | |
{ | |
def selected = table.getSelection().first().text.toInteger(); | |
def entry = allPosts[selected] | |
def html = entry.content[0].value()[0]; | |
browser.setText(html); | |
} | |
catch(Exception ex) | |
{ | |
_eclipse.log("ERROR: " + ex.getMessage()); | |
} | |
}}); | |
table.columns("#", "title", "publish date", "categories","content"); | |
def count = 1; | |
for(def entry in allPosts)//.take(20)) | |
{ | |
def title = entry.title[0].value()[0]; | |
def publishDate = entry.published[0].value(); | |
def categories = entry.category.collect { it.attributes().term}.drop(1).sort() | |
def content = entry.content[0].value()[0]; | |
table.add_Row(count++, title, publishDate, categories, content); | |
} | |
return "done"; | |
//Config:UIThread_False |
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
def xmlFile = "/Users/plugin/Downloads/blog-03-09-2014.xml"; | |
def xmlParser = new XmlParser(); | |
def xml = xmlParser.parse(xmlFile) | |
def postCategory = "http://schemas.google.com/blogger/2008/kind#post"; | |
def categoryFilter = "AngularJS"; | |
def allPosts = xml.entry.findAll { it.category[0] .attributes().term == postCategory && | |
it.category.collect().toString().contains(categoryFilter) && | |
it["app:control"].size() == 0}; |
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
def categoryFilter = "Git"; | |
def exportXmlFile = "/Users/plugin/_Books/Posts_with_Only_${categoryFilter}.xml"; | |
//*** Step 1) load the original blogger export | |
def xmlFile = "/Users/plugin/Downloads/blog-03-09-2014.xml"; | |
def xmlParser = new XmlParser(); | |
def xml = xmlParser.parse(xmlFile) | |
def postCategory = "http://schemas.google.com/blogger/2008/kind#post"; | |
def pageCategory = "http://schemas.google.com/blogger/2008/kind#page"; | |
// get all posts | |
def allPosts = xml.entry.findAll { it.category[0] .attributes().term == postCategory && it["app:control"].size() == 0}; | |
def allDrafts = xml.entry.findAll { it.category[0] .attributes().term == postCategory && it["app:control"].size() > 0} | |
def allPages = xml.entry.findAll { it.category[0] .attributes().term == pageCategory } | |
//*** Step 3) remove all posts that dont match the categoryFilter value | |
def allPostsToRemove = allPosts.findAll { it.category.collect().toString().contains(categoryFilter)==false } | |
for(def postToRemove in allPostsToRemove) | |
xml.remove(postToRemove); | |
for(def postToRemove in allDrafts) | |
xml.remove(postToRemove); | |
for(def postToRemove in allPages) | |
xml.remove(postToRemove); | |
//*** Step 4) write file (making sure it is in utf-8 format | |
def outputStreamWritter = new OutputStreamWriter(new FileOutputStream(exportXmlFile),"UTF-8"); | |
def bufferedWriter = new BufferedWriter (outputStreamWritter); | |
def printWriter = new PrintWriter(bufferedWriter) | |
def xmlNodePrinter = new XmlNodePrinter(printWriter); | |
xmlNodePrinter.print(xml); | |
//*** Step5) load the exportXmlFile (to that we can show it on the Eclipse view | |
xml = xmlParser.parse(exportXmlFile) | |
allPosts = xml.entry.findAll { it.category[0] .attributes().term == postCategory }; | |
//create view | |
def view = eclipse.views.create("Blogger data viewer").clear(); | |
def table = view.add.table(); | |
def browser = view.add.browser(); | |
def _eclipse = eclipse; | |
//set event to show selected row on browser | |
table.set.event.onSelection(new Runnable() { public void run() | |
{ | |
try | |
{ | |
def selected = table.getSelection().first().text.toInteger() -1; | |
def entry = allPosts[selected] | |
def html = entry.content[0].value()[0]; | |
browser.setText(html); | |
} | |
catch(Exception ex) | |
{ | |
_eclipse.log("ERROR: " + ex.getMessage()); | |
} | |
}}); | |
//set table columns and add rows | |
table.columns("#", "title", "publish date", "categories","content"); | |
def count = 1; | |
for(def entry in allPosts) //.take(20)) | |
{ | |
def title = entry.title[0].value()[0]; | |
def publishDate = entry.published[0].value(); | |
def categories = entry.category.collect { it.attributes().term}.drop(1).sort() | |
def content = entry.content[0].value()[0]; | |
table.add_Row(count++, title, publishDate, categories, content); | |
} | |
return "done"; | |
//Config:UIThread_False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment