Ejemplo n.º 1
0
def generate_xml():
	tree = ET.parse(Settings.local_base_xml_filename())
	root = tree.getroot()
	channel = root.find('channel')

	# Alter the title of this podcast to append ' (Cached)'
	title = channel.find('title')
	title.text += ' (Cached)'

	# Remove any existing items from the channel tag in the base XML file
	items = channel.findall("item")
	for item in items:
		channel.remove(item)

	# Now... add every episode we've got
	for number in range(1, Settings.get_highest_episode()+1):
		print "Processing " + str(number)
		try:
			channel.append(process_episode(number))
		except Exception as e:
			print "Something bad happened while processing episode " + str(number)
			print "{0}".format(e)
			print "{0}".format(sys.exc_info()[0])
			print "{0}".format(sys.exc_info()[1])
			traceback.print_tb(sys.exc_info()[2])
	
	#output = prettify(root).encode('utf-8')
	#output = prettify(channel).encode('utf-8')
	
	#with open(LOCAL_RSS_FILE, "w") as f:
	#	f.write(output)
	tree.write(Settings.local_xml_filename())
	print "You can download the mirrored podcast from:"
	print "   " + Settings.local_xml_url()
Ejemplo n.º 2
0
def update_cache():
	# First, make sure that the base XML file is here
	if not os.path.isfile(Settings.local_base_xml_filename()):
		print "Looks like we need to fetch the XML file"
		fetch_xml()

	# Next, try to get any missing episodes
	for number in Settings.get_missing_episodes():
		if Settings.have_podcast(number):
			print "Looks like we already had podcast #{0}".format(number)
			Settings.remove_missing_episode(number)
		else:
			print "Trying to fetch missing episode #{0}".format(number)
			if fetch_pair(number):
				print "   Got it!"
				Settings.remove_missing_episode(number)
			else:
				print "   Failed again"

	# Now, try getting episodes beyond what we already have
	number = Settings.get_highest_episode() + 1
	missing = []
	while len(missing) < Settings.MAX_CONSECUTIVE_404S:
		if Settings.have_podcast(number):
			print "Looks like we already had podcast #{0}".format(number)
			Settings.set_highest_episode(number)
		else:
			print "Checking to see if episode {0} is there".format(number)
			if fetch_pair(number):
				print "   Got it!"
				Settings.set_highest_episode(number)
				# Did we miss some before this? If so, mark them as missed
				if len(missing) > 0:
					for num in missing:
						Settings.add_missing_episode(num)
			else:
				print "   Not there."
				missing.append(number)
			# Otherwise, try for the next episode
		number += 1
	print "Looks like {0} is the highest episode number, so far.".format(Settings.get_highest_episode())