Code: Select all
/**
* author: chr1s <hacker-org@woernswildweb.de>
* name: OneMinuteMan.groovy
* description: Solution for challenge "One Minute Man" @ http://www.hacker.org
* date: 20090306
*/
def url = new URL("http://www.hacker.org/challenge/misc/minuteman.php");
def bResult = false;
while (!bResult) {
try {
def httpConnection = url.openConnection();
def result = httpConnection.inputStream.getText();
if(!result.contains("back later")){
println("It is currently ${ new Date() }");
println("We got it! The result is:");
println(result);
bResult = true;
} else {
println("It is currently ${ new Date() }");
println("There is no result this time...");
}
// Wait 30 sec.
sleep(30000);
// The connection times out sometimes and it is possible to get
// other exceptions, so we catch them all...
} catch (Exception e) {
println("It is currently ${ new Date() }");
println("Error while connecting server!");
sleep(10000);
}
}
chr1s