Groovy March Madness

Posted by: Pratik Patel on 03/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.


About Pratik Patel

Pratik Patel

Pratik Patel is the CTO of Atlanta based TripLingo (http://www.triplingo.com/). He wrote the first book on 'enterprise Java' in 1996, "Java Database Programming with JDBC." He has also spoken at various conferences and participates in several local tech groups and startup groups. He's in the startup world now and hacks iOS, Android, HTML5, CSS3, JavaScript, Rails, and ..... well everything except Perl.

Pratik's specialty is in large-scale applications for mission-critical and mobile applications use. He has designed and built applications in the retail, health care, financial services, and telecoms sectors. Pratik holds a master's in Biomedical Engineering from UNC, has worked in places such as New York, London, and Hong Kong, and currently lives in Atlanta, GA.

More About Pratik »

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 7
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 3
  • Automation Tools: Git, Hudson, Sonar
  • HTML5, Ajax, jQuery, Usability
  • Mobile Applications - iPhone and Android
  • More...
Learn More »

NFJS, the Magazine

December Issue Now Available
  • BDD and REST

    by Brian Sletten
  • Mocks and Stubs in Groovy Tests

    by Kenneth Kousen
  • Algorithms for Better Text Search Results

    by John Griffin
  • Knowns and Unknowns of Scrum and Agile

    by Brian Tarbox
Learn More »