Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Oct 9, 2014

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.