import org.microformats.hCard.hCardParser
class PhotoCheckerJob {
	//def timeout = 10000l
	def startDelay = 5000
	def timeout = 21600000l     // execute job once in 12 hours

    def execute() {
	    //This assumes there is a property named
	    //photoUrl and url in the Comment class
	    //Adjust accordingly
	    println "photochecker"
	    def crit = Comment.createCriteria()
	    def results = crit.list {
	    	and {
	    		isNull("photoUrl")
	    		isNotNull("website")
	    		ne("website","")
	    	}
	    }
	    results.each {
	    	try {
	    	println "trying to locate hCard"
	    	println it.name + ' '+it.website
	    	def hCard = hCardParser.parseOne(it.website)
	    	println hCard == null
	    	it.photoUrl = hCard?.photos?.get(0)
	    	it.save()
	    	} catch (Exception e) { }
	    }
	}
}
