def run(): logger.info("Retrieving myepisodes list") raw_feed = url.urlopen(config.val("rss")).read() title_list = re.findall("<title>(.*?)</title>", raw_feed) # Counting results, using a flag results = 0 downloaded_flag = 0 # Notification text - this var is updated each time a torrent is successfully found body = "Downloading episodes:\n" for title in title_list: title_cut = re.findall("\[ (.*?) \]", title) dropped_shows = config.dropped_shows() # If title is "", it's not a show. Also filtering according to specified year, and skipping some specific shows if len(title_cut) == 0: logger.info("Skipping empty line") continue elif int(title_cut[3][-4:]) < config.val("limit_date"): logger.info("Skipping show older than limit date (" + title_cut[3][-4:] + ")") continue elif title_cut[0] in dropped_shows: logger.info("Skipping specific show") continue else: results += 1 episode_nbr = "S" + title_cut[1][:2] + "E" + title_cut[1][-2:] episode = title_cut[0] + " " + episode_nbr logger.info("Found episode : " + episode) # Searching episode, updating body notification if download has started logger.info("Searching episode") downloaded = torrent.download(episode) if downloaded: body = body + downloaded + "\n" downloaded_flag = 1 # If nothing new, or could not fetch anything if results == 0 or downloaded_flag == 0: logger.info("Nothing new today") else: # Pushing notification logger.info("Pushing notification") config.notification(body) # Writing logs for web interface write_logs(body) return results
def dbus_error_handler(self, error): err_name = error.name if 'InProgress' in err_name: if self.net_disconnected != 1: self.disconnect_network() else: self.net_disconnected = 0 self.connect_network() else: err_message = error.message if 'Operation aborted' in err_message or 'Input/output error' in err_message: if oe.input_request: oe.input_request = False self.connect_attempt = 0 self.log_error = 1 self.notify_error = 0 elif self.connect_attempt == 1: self.log_error = 0 self.notify_error = 0 oe.xbmcm.waitForAbort(5) self.connect_network() else: self.log_error = 1 self.notify_error = 1 elif 'Did not receive a reply' in err_message: self.log_error = 1 self.notify_error = 0 else: self.log_error = 1 self.notify_error = 1 if self.notify_error == 1: config.notification(err_message, 'Network Error') else: self.notify_error = 1 if self.log_error == 1: log.log(repr(error), log.ERROR) else: self.log_error = 1
def report_error(self, path, error): oe.input_request = False config.notification(error)
# Returns IMDb ID, Title and Year def imdb_info(title): data = urllib2.urlopen("http://www.omdbapi.com/?i=&t="+urllib.quote_plus(title)) d = json.load(data) return "http://www.imdb.com/title/"+d['imdbID'], d['Title'], d['Year'] if __name__ == "__main__": form = cgi.FieldStorage() title, option = form['title'].value, form['option'].value logger.info("User input "+title+" added for "+option) # At this point, if a year is specified for searches, it is ignored try: imdb_url, imdb_title, imdb_year = imdb_info(title.split("(")[0]) logger.info("Omdbapi search result "+imdb_url+" "+imdb_title+" "+imdb_year) except: logger.info("Omdbapi search not performed") if option=="download": # Removing parentheses for search's sake title = title.replace('(', '').replace(')', '') result = download(title) if result is not None: # Need to return data to Javascript, so that it knows this was successful print "ok" config.notification("Downloading:\n"+imdb_title+" ("+imdb_year+")", imdb_url) elif option=="search": # Adding pretty parentheses print imdb_title+" ("+imdb_year+")"
cmd1 = ["ip", "-6", "addr"] cmd2 = ["grep", "scope global dynamic"] cmd3 = ["cut", "-d", ' ', "-f6"] p1 = sp.Popen(cmd1, stdout=sp.PIPE) p2 = sp.Popen(cmd2, stdin=p1.stdout, stdout=sp.PIPE) p3 = sp.Popen(cmd3, stdin=p2.stdout, stdout=sp.PIPE) actual_ipv6, err=p3.communicate() cmd1 = ["wget", "http://ipinfo.io/ip", "-qO", "-"] p1 = sp.Popen(cmd1, stdout=sp.PIPE) actual_ipv4, err=p1.communicate() if actual_ipv6!='' and actual_ipv4!='': if actual_ipv6 != previous_ipv6: alert = alert + "IPv6 has changed! " alert = alert + "Previous one: "+previous_ipv6+" " alert = alert + "New one: "+actual_ipv6+" " if actual_ipv4 != previous_ipv4: alert = alert + "IPv4 has changed! " alert = alert + "Previous one: "+previous_ipv4+" " alert = alert + "New one: "+actual_ipv6+" " ip_file = open('ip.log','w') ip_file.write(actual_ipv6) ip_file.write(actual_ipv4) if alert!="": config.notification(alert)
#!/usr/bin/env python import urllib2, config from lxml import etree if __name__ == "__main__": data = urllib2.urlopen("http://www.arte.tv/papi/tvguide-flow/feeds/program/fr.xml") tree = etree.parse(data) for item in tree.xpath("/rss/channel/item[category='Film']"): movie = item.getchildren() config.notification("ARTE - " + movie[0].text, movie[1].text)