Last active
December 16, 2015 17:49
-
-
Save fabito/5472985 to your computer and use it in GitHub Desktop.
Script used to play a sound when a specific image is present in a page. It fetches the page every 5 minutes and checks for the image presence.
If the image is found it starts playing the alarm in a loop.
This file contains hidden or 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
#!/usr/bin/env groovy | |
@Grapes( @Grab('org.jsoup:jsoup:1.6.1')) | |
import org.jsoup.* | |
import org.jsoup.nodes.* | |
// a wrapper closure around executing a string | |
// can take either a string or a list of strings (for arguments with spaces) | |
// prints all output, complains and halts on error | |
def runCommand = { strList -> | |
assert ( strList instanceof String || ( strList instanceof List && strList.each{ it instanceof String })) | |
def proc = strList.execute() | |
proc.in.eachLine { line -> println line } | |
proc.out.close() | |
proc.waitFor() | |
print "[INFO] ( " | |
if(strList instanceof List) { | |
strList.each { print "${it} " } | |
} else { | |
print strList | |
} | |
println " )" | |
if (proc.exitValue()) { | |
println "gave the following error: " | |
println "[ERROR] ${proc.getErrorStream()}" | |
} | |
assert !proc.exitValue() | |
} | |
found = false | |
img2find = 'http://imageshack.us/a/img834/2894/topoamineirogeral.jpg' | |
while (!found) { | |
try { | |
println 'fetching page...' | |
Document doc = Jsoup.connect("http://www.totalacesso.com/event/detail/421").get(); | |
def results = doc.select("div.ContentEventDetail img") | |
println "looking for image: $img2find" | |
if(results.find { it.attr('src').equals(img2find)}) { | |
println "Image found!!" | |
found = true | |
} else { | |
println 'Not yet.. Sleeping...' | |
doc.sleep(300000) | |
println 'Trying again...' | |
} | |
} catch(Throwable t) {} | |
} | |
if (found) | |
while(true) | |
runCommand('paplay /usr/share/sounds/ubuntu/stereo/phone-incoming-call.ogg') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment