Groovy March Madness - No Fluff Just Stuff

Groovy March Madness

Posted by: Pratik Patel on March 25, 2009

So now that the annual basketball tournament is underway, I thought I'd share my latest tool for becoming master of your tournament pool. Here's a neat little groovy script to extract the stats for a team.

import groovyx.net.http.HTTPBuilder import groovyx.net.http.Method import static groovyx.net.http.ContentType.TEXT class TeamStats extends GroovyTestCase { def void test_parseTeamStat() { def page = getPage('http://www.cbssports.com/collegebasketball/teams/stats/NC/regularseason/yearly/SCORING') def playerTable = page.body.div.table.tr.td.div.div.table playerTable.tr.list().each { row -> row.td.list().each { column -> print "${column}\t" } println "" } } def getPage(url) { def page def http = new HTTPBuilder(url) http.request(Method.POST,TEXT) { req -> response.success = { resp,reader -> //println resp.headergroup.allHeaders() def parser = new org.ccil.cowan.tagsoup.Parser() page = new XmlSlurper(parser).parse(reader) } response.failure = { // do something here } } return page } }

I take these stats, dump them into a database, and create a few graphs and stat comparisons to figure out my picks. Problem is that I went with my 'gut' rather than the stats.

Pratik Patel

About Pratik Patel

Pratik Patel is a Java Champion and developer advocate at Azul Systems and has written 3 books on programming (Java, Cloud and OSS). An all around software and hardware nerd with experience in the healthcare, telecom, financial services, and startup sectors. He's also a co-organizer of the Atlanta Java User Group and North Atlanta JavaScript meetup, frequent speaker at tech events, and master builder of nachos.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »