@@ -0,0 +1,1850 @@
+#!/usr/bin/env python%0A'''%0AScript for removing Harmatheque e-book records from MARS R00 report.%0ACreated for the Harvard Library ITS MARS Reports Pilot Project, 2014.%0A'''%0Aimport codecs%0Aimport csv%0Aimport glob%0Aimport requests%0Aimport time%0Afrom lxml import html%0A%0Anets = %5B%5D%0Anot_nets = %5B%5D%0A%0A%0Acounter = 0%0A%0Afor file in glob.glob('*.csv'):%0A    with open(file, 'rb') as mars_csv:%0A        reader = csv.reader(mars_csv)%0A        for row in reader:%0A            if row%5B15%5D == 'NET (GEN)':%0A                bib = row%5B1%5D%0A                marc_url = 'http://webservices.lib.harvard.edu/rest/marc/hollis/' + bib%0A                presto = requests.get(marc_url)%0A                marc_xml = presto.content.replace('%3Crecord xmlns=%22http://www.loc.gov/MARC21/slim%22 xmlns:xsi=%22http://www.w3.org/2001/XMLSchema-instance%22 xsi:schemaLocation=%22http://www.loc.gov/MARC21/slim   http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd%22%3E','%3Crecord%3E')%0A                marc_record = html.fromstring(marc_xml)%0A                if marc_record.xpath('//leader/text()'):%0A                    h09 = marc_record.xpath('//datafield%5B@tag=%22H09%22%5D/subfield%5B@code=%22m%22%5D/text()') # Get list of H09 subfield m fields%0A                if 'harmatheque' in h09:%0A                    nets.append(row)%0A                    %0A                else:%0A                    not_nets.append(row)%0A                time.sleep(1)%0A            else:%0A                not_nets.append(row)%0A%0Aif len(nets) %3E 0:%0A    with open('r00_harmatheque.csv', 'wb') as output:%0A        output.write(codecs.BOM_UTF8)%0A        writer = csv.writer(output, quoting=csv.QUOTE_ALL,quotechar='%22')%0A        writer.writerows(nets)%0Aif len(not_nets) %3E 0:%0A    with open('r00_not_harmatheque.csv', 'wb') as output:%0A        output.write(codecs.BOM_UTF8)%0A        writer = csv.writer(output, quoting=csv.QUOTE_ALL,quotechar='%22')%0A        writer.writerows(not_nets)%0A

Add script for removing e-book records