Groovy CLI application for Podcast reporting

I wrote a small Micronaut Framework command line application to output a CSV file with a podcast's episode titles, authors, and release dates. Micronaut CLI applications use Picocli.

Working with XML and Apache Groovy is easy.

The core functionality is only a few lines of Apache Groovy code:

@CompileDynamic
void run() {
    String text = new URL(url).text
    def rss = new XmlSlurper().parseText(text)
    List<Episode> episodeList = []
    String publication = DateTimeFormatter.ISO_DATE.format(
        DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss z")
            .parse(it.pubDate as String))
    rss.channel.item.each {
        episodeList << new Episode(title: it.title, 
                                   author: it.author, 
                                   publication: publication)
    String result = episodeList.sort({a, b -> b.publication <=> a.publication})
        .collect {it -> "${it.title},${it.author},${it.publication}"}.join("\n")
    if (verbose) {
        println result
    }
    output.text = result
}

Go to the linked site

Tags: #micronaut #groovy #picocli