def run(self): with wyvern.LOCK: wyvern.SHOW_INSTANCES = [] logger.debug("Updating Shows") if wyvern.MANAGED_SHOWS is None: return for tracked_show in wyvern.MANAGED_SHOWS: if wyvern.STOP_EVENT.isSet(): return new_show = show.Show(tracked_show["name"], tracked_show["tvdbid"], tracked_show["format"]) new_show.feed = tracked_show["feed"] wyvern.SHOW_INSTANCES.append(new_show)
def run(self): with wyvern.LOCK: if wyvern.SB_URL is None or wyvern.SHOW_INSTANCES is None or wyvern.TORRENT_BLACKHOLE is None: return logger.info("Checking on downloads") for show in wyvern.SHOW_INSTANCES: if wyvern.STOP_EVENT.isSet(): return logger.debug("Checking on show: " + show.ShowName) if show.feed is None: logger.warning("Show {0} has no download feed".format(show.ShowName)) continue feed = feedparser.parse(show.feed) for e in feed['entries']: filename = e['title'] file_info = show.parse_filename(filename) if file_info is None: continue sb_url = "{0}/?cmd=episode&tvdbid={1}&season={2}&episode={3}&full_path=1" \ .format(wyvern.SB_URL, show.TheTvDbId, file_info.Season, file_info.Episode) show_json = requests.get(sb_url).json() if 'result' not in show_json or show_json['result'] <> 'success': if int(file_info.Season) >= 0 and int(file_info.Episode) >= 0: logger.warning( "Could not poll sickbeard for show {0}({1}) - S{2:02d}E{3:02d}" .format(show.ShowName, show.TheTvDbId, int(file_info.Season), int(file_info.Episode))) continue show_data = show_json['data'] status = show_data['status'] airdate = show_data['airdate'] if not (status.upper() == 'WANTED' or (status.upper() == 'UNAIRED' and time.strptime(airdate, "%Y-%m-%d") <= datetime.datetime.now( ).timetuple())): continue torrent_link = e['link'] logger.debug("from " + torrent_link) logger.info("Downloading Torrent for show {0} - S{1:02d}E{2:02d}" .format(show.ShowName, int(file_info.Season), int(file_info.Episode))) r = requests.get(torrent_link) if not r.status_code == requests.codes.ok: logger.warning( "Could not update sickbeard for show {0} - S{1:02d}E{2:02d}" .format(show.ShowName, int(file_info.Season), int(file_info.Episode))) continue f = open(os.path.join(wyvern.TORRENT_BLACKHOLE, filename.replace(' ', '_') + ".torrent"), 'w') f.write(r.content) f.close() sb_url = "{0}/?cmd=episode.setstatus&tvdbid={1}&season={2}&episode={3}&status=skipped".format( wyvern.SB_URL, show.TheTvDbId, file_info.Season, file_info.Episode) logger.debug("Updating sickbeard with URL " + sb_url) result_json = requests.get(sb_url).json() logger.debug("Result: " + result_json['result'])
prev = os.umask(0) os.umask(prev and int('077', 8)) # Make the child a session-leader by detaching from the terminal try: pid = os.fork() # @UndefinedVariable - only available in UNIX if pid != 0: os._exit(0) except OSError, e: sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror)) sys.exit(1) # Write pid if wyvern.CREATE_PID: pid = str(os.getpid()) logger.debug(u"Writing PID: " + pid + " to " + str(wyvern.PID_FILE)) try: file(wyvern.PID_FILE, 'w').write("%s\n" % pid) except IOError, e: logger.error(u"Unable to write PID file: " + wyvern.PID_FILE + " Error: " + str(e.strerror) + " [" + str( e.errno) + "]") wyvern.halt() # Redirect all output sys.stdout.flush() sys.stderr.flush() devnull = getattr(os, 'devnull', '/dev/null') stdin = file(devnull, 'r') stdout = file(devnull, 'a+') stderr = file(devnull, 'a+')
def save_main(self, *args, **kwargs): logger.debug("Saving Main") self.index(self)
def save_settings(self, data, data2): logger.debug("Saving Settings") cl = cherrypy.request.headers['Content-Length'] rawbody = cherrypy.request.body.read(int(cl)) logger.debug(rawbody)