def process_destinations(file_name, taxonomies, template_file, output_location): """ Process each <destination> in the xml file into its own file based on `template_file` :param: file_name (string/path) - full_path to the destinations.xml :param: taxonomies (dict) - double linked list of all the menu items :param: template_file (string/path) - full path to the template file :param: output_location (string/path) - where each processed destination should be stored """ destination = None for event, elem in ET.iterparse(file_name, events=('start','end',)): if elem.tag == 'destination': if event == 'start': location = elem.get('title') geo_id = elem.get('atlas_id') # build a destination.html file_name = os.path.join(output_location, "%s.html" % Destination.sanitize_name(location)) fp = open(file_name, 'w') destination = Destination(location, fp) else: destination.write_blocks_to_template(taxonomies, geo_id, template_file) print "processed: %s" % location if destination: for text_item in elem.itertext(): destination.build_block(elem.tag, text_item)
def test_sanitize_name(self): self.assertEqual(Destination.sanitize_name('Africa'), 'africa') self.assertEqual(Destination.sanitize_name('Port Sudan'), 'port_sudan') self.assertEqual(Destination.sanitize_name('KwaZulu-Natal'), 'kwazulu-natal')