Vous êtes sur la page 1sur 6

#!/usr/bin/env python try: import xml.etree.cElementTree as ET except ImportError: import xml.etree.ElementTree as ET parser = ET.XMLParser(encoding="cp1252") tree = ET.parse("AllMedia.

xml", parser=parser) root = tree.getroot() yes = 'filled in ' no = 'empty ' def printrows(): for record in root.findall('Records'): title = record.find('mediaTitle').text subtitle = record.find('mediaSubTitle').text author = record.find('mediaAuthorString').text print title print subtitle print author print '---' def countcats(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaCatNumber').text if x == 'NULL': i += 1 elif x == '': i += 1 else: j += 1 print yes + 'cat numbers: ' + str(j) print no + 'cat numbers: ' + str(i) print '---' def countbars(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaBarcodeNumber').text if x == 'NULL': i += 1 elif x == '': i += 1 else: j += 1 print yes + 'barcodes: ' + str(j) print no + 'barcodes: ' + str(i) print '---' def counttitles(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaTitle').text

if x == 'NULL': i += 1 elif x == '': i += 1 else: j += 1 print yes + 'titles: ' + str(j) print no + 'titles: ' + str(i) print '---' def countauthors(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaAuthorString').text if x == 'NULL': i += 1 elif x == '': i += 1 else: j += 1 print yes + 'authors: ' + str(j) print no + 'authors: ' + str(i) print '---' def countpubs(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaPublisher').text if x == 'NULL': i += 1 elif x == '': i += 1 else: j += 1 print yes + 'publishers: ' + str(j) print no + 'publishers: ' + str(i) print '---' def countisbns(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaISBN').text if x == 'NULL': i += 1 elif x == '': i += 1 else: j += 1 print yes + 'ISBNS: ' + str(j) print no + 'ISBNS: ' + str(i) print '---' def counttypes(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaType').text

if x == 'NULL': i += 1 elif x == '': i += 1 else: j += 1 print yes + 'types: ' + str(j) print no + 'types: ' + str(i) print '---' def countlangs(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaLanguage').text if x == 'NULL': i += 1 elif x == '': i += 1 else: j += 1 print yes + 'languages: ' + str(j) print no + 'languages: ' + str(i) print '---' def counttargets(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaTarget').text if x == 'NULL': i += 1 elif x == '': i += 1 else: j += 1 print yes + 'targets: ' + str(j) print no + 'targets: ' + str(i) print '---' def countother(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaOtherNumber').text if x == 'NULL': i += 1 elif x == '': i += 1 else: j += 1 print x print yes + 'other numbers: ' + str(j) print no + 'other numbers: ' + str(i) print '---' def countweb(): i = 0 j = 0 for record in root.findall('Records'):

x = record.find('mediaWebsite').text if x == 'NULL': i += 1 elif x == '': i += 1 else: j += 1 print yes + 'websites: ' + str(j) print no + 'websites: ' + str(i) print '---' def countmulti(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaMultimedia').text if x == 'NULL': i += 1 elif x == '': i += 1 else: j += 1 print yes + 'multimedia: ' + str(j) print no + 'multimedia: ' + str(i) print '---' def countprice(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaPrice').text if x == 'NULL': i += 1 elif x == '': i += 1 elif x == '0.00': i += 1 else: j += 1 print yes + 'prices: ' + str(j) print no + 'prices: ' + str(i) print '---' def countvalue(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaValue').text if x == 'NULL': i += 1 elif x == '': i += 1 elif x == '0.00': i += 1 else: j += 1 print yes + 'values: ' + str(j) print no + 'values: ' + str(i) print '---'

def countspine(): i = 0 j = 0 h = 0 for record in root.findall('Records'): x = record.find('mediaSpineLabelPrinted').text if x == 'False': i += 1 elif x == 'True': j += 1 else: h += 1 print 'spine label printed true: ' + str(j) print 'spine label printed false: ' + str(i) print 'empty: ' + str(h) print '---' def countlabel(): i = 0 j = 0 h = 0 for record in root.findall('Records'): x = record.find('mediaLabelPrinted').text if x == 'False': i += 1 elif x == 'True': j += 1 else: h += 1 print 'label printed true: ' + str(j) print 'label printed false: ' + str(i) print 'empty: ' + str(h) print '---' def countlang(): i = 0 j = 0 for record in root.findall('Records'): x = record.find('mediaLanguage').text if x == 'NULL': i += 1 elif x == '': i += 1 elif x == '0.00': i += 1 else: j += 1 print yes + 'languages: ' + str(j) print no + 'languages: ' + str(i) print '---' counttitles() countauthors() countpubs() countcats() countbars() countisbns() counttypes() countlangs() counttargets()

countother() countweb() countmulti() countprice() countvalue() countspine() countlabel() countlang()

Vous aimerez peut-être aussi