Created
October 9, 2014 18:54
-
-
Save bdkosher/faad7750e15671c44b95 to your computer and use it in GitHub Desktop.
Counts the number of tagged questions on Stackoverflow for a given tag.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍