/* Daily Email Alerts for Late Night Talk Shows Last Modified: 06 Nov 2011 Author: Derek Battams Run this script daily to produce a report of the evening's late night talk shows. Each show includes a link to the web interface, which will allow you to record the airing, if so desired. I used to just put a lot of the talk shows in my favs then mark them as watched if the guests didn't interest me. This required me to remember to mark them as watched or I ended up with a bunch of recordings I didn't really want. Now I get this email every morning and if the guest list interests me then I just click the link to setup the recording. If I'm not interested then nothing ever gets recorded. You MUST change the settings below, especially the email settings if you want this script to email the output. The script is written for the SJQv4 environment and expects it is running in that environment. */ def BASE_URL = 'http://192.168.1.10:8086/sage' // Base URL to web interface, with NO trailing slash class EmailSettings { static def sendMail = true // Set this to false to just dump the alert msg to stdout instead of emailing it static def host = '' static def user = '' static def pwd = '' static def port = '80' static def subj = 'Tonight\'s Late Night Talk' static def from = user // Gmail will reject mail via SMTP if the from addr != user id so no point in changing this static def to = '' // Sometimes Gmail won't send an email addressed to yourself, try a plus address at the end; YMMV static def ssl = 'false' // Gmail requires SSL, other SMTP servers may or may not; this is a STRING setting! } def sendMail(def msg) { def ant = new AntBuilder() ant.mail(mailhost: EmailSettings.host, mailport: EmailSettings.port, subject: EmailSettings.subj, user: EmailSettings.user, password: EmailSettings.pwd, ssl: "false") { from(address: EmailSettings.from) to(address: EmailSettings.to) message(msg) } } def noAiringWillRecord(def air, def start, def end) { def expr = "GetAiringsForShow(GetShowForExternalID(\"${ShowAPI.GetShowExternalID(air)}\"), \"${start - 1000}\")" for(def a : Database.FilterByRange(WidgetAPI.EvaluateExpression(expr), 'GetAiringStartTime', start, end, true)) if(AiringAPI.IsManualRecord(a)) return false return true } def start = new Date() start[Calendar.HOUR_OF_DAY] = 22 start[Calendar.MINUTE] = 0 start[Calendar.SECOND] = 0 def end = new Date(start.getTime() + 6L * 3600000L) def shows = new HashSet() def airings = [] Database.FilterByBoolMethod(Database.FilterByBoolMethod(Database.FilterByMethod(Database.FilterByMethod(Database.GetAiringsOnViewableChannelsAtTime(start.getTime(), end.getTime(), true), 'GetShowCategory', 'Talk', true), 'GetShowSubCategory', 'Comedy', true), 'IsShowFirstRun', true), 'IsNotManualOrFavorite', true).each { if(ShowAPI.GetShowDescription(it) && noAiringWillRecord(it, start.getTime(), end.getTime()) && shows.add(ShowAPI.GetShowExternalID(it))) airings << it } def msg = new StringBuilder() airings.each { msg << "${ShowAPI.GetShowTitle(it)}\n" msg << "${ShowAPI.GetShowDescription(it)}\n" msg << "${BASE_URL}/DetailedInfo?AiringId=${AiringAPI.GetAiringID(it)}\n\n" } if(EmailSettings.sendMail && msg.toString()) sendMail(msg.toString()) else if(msg.toString()) println msg return 0