Created
February 16, 2015 00:06
-
-
Save muschneider/805629395cbbf362b166 to your computer and use it in GitHub Desktop.
Groovy example to delete all delicious links
This file contains hidden or 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
import javax.net.ssl.HttpsURLConnection | |
import java.net.* | |
import java.io.* | |
def userName = "" | |
def passWord = "" | |
if (this.args.length == 2) { | |
userName = this.args[0] | |
passWord = this.args[1] | |
} else { | |
println "use: groovy rm_delicious_links <delicious_user_name> <delicious_password> " | |
return -1 | |
} | |
Authenticator.setDefault(new Authenticator() { | |
PasswordAuthentication getPasswordAuthentication() { | |
return new PasswordAuthentication(userName ,passWord.toCharArray()) | |
} | |
}); | |
def url = new URL("https://${userName}:${passWord}@api.del.icio.us/v1/posts/all") | |
def posts = new XmlParser().parseText(url.text) | |
posts.each{ pAttr -> | |
def href = pAttr.attribute("href") | |
def urlDelete = "https://${userName}:${passWord}@api.del.icio.us/v1/posts/delete?&url=${href}".toURL() | |
def conn = urlDelete.openConnection(); | |
conn.connect(); | |
if ( conn instanceof HttpURLConnection) { | |
def httpConnection = (HttpURLConnection) conn | |
code = httpConnection.getResponseCode() | |
if (code == 200) println "url ${href} deleted" | |
else println "error to delete ${href} with status code: ${code}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment