Skip to content

Instantly share code, notes, and snippets.

@bdkosher
Created October 9, 2014 18:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdkosher/faad7750e15671c44b95 to your computer and use it in GitHub Desktop.
Save bdkosher/faad7750e15671c44b95 to your computer and use it in GitHub Desktop.
Counts the number of tagged questions on Stackoverflow for a given tag.
@Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='1.2')
import java.text.*
class SOTagCounter {
def parser = new XmlSlurper(new org.ccil.cowan.tagsoup.Parser())
int count(String tag) {
new URL("http://stackoverflow.com/questions/tagged/${new URI(tag).path}").withReader { page ->
def html = parser.parse(page)
def c = html.body.div.find { it.@class == 'container' }.div.find { it.@id == 'content' }.div.find { it.@id == 'sidebar' }.div.find { it.@class == 'module' }.div[0].text()
c ? new DecimalFormat('#,###').parse(c) : 0
}
}
}
def a = new SOTagCounter()
assert a.count('java') > a.count('c#')
assert a.count('svn') < a.count('git')
assert a.count('groovy') >= 10_000 // woot
@sbglasius
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment