def test_03(self): mdate = modesdatefrombritishdate('12.3.1917') self.assertEqual(mdate, ('12.3.1917', 3, MODESTYPE))
def test_06(self): mdate = modesdatefrombritishdate('March 1917') self.assertEqual(mdate, ('3.1917', 2, BRITISHTYPE))
def test_01(self): mdate = modesdatefrombritishdate('12 Mar 1917') self.assertEqual(mdate, ('12.3.1917', 3, BRITISHTYPE))
def main(): global nrows if not _args.noprolog: outfile.write(b'<?xml version="1.0"?><Interchange>\n') global_object_template = None if _args.template: global_object_template = get_object_from_file(_args.templatefile) reader = csv.DictReader(incsvfile) trace(1, 'CSV Column Headings: {}', reader.fieldnames) nrows = 0 # PyCharm whines if we don't initialize accnumgen accnumgen = next_accnum(_args.acc_num) for row in reader: emit = True if global_object_template: template = copy.deepcopy(global_object_template) else: template = get_template(row) elt = template.find('./ObjectIdentity/Number') if _args.acc_num: accnum = next(accnumgen) trace(2, 'Serial generated: {}', accnum) else: accnum = row[_args.serial] # TODO: validate the accession number; must be like 2022.12[.2] if config.add_mda_code and accnum[0].isnumeric(): accnum = _args.mdacode + '_' + accnum elt.text = accnum for doc in config.col_docs: cmd = doc[Stmt.CMD] title = doc[Stmt.TITLE] if cmd != Cmd.CONSTANT and not row[title]: trace(3, '{}: cell empty {}', accnum, title) continue xpath = doc[Stmt.XPATH] if xpath.lower() == Stmt.FILLER: continue elt = template.find(xpath) if elt is None: elt = new_subelt(doc, template, _args.verbose) if elt is None: trace( 1, '{}: Cannot create new {}.\nCheck parent_path statement.', accnum, doc[Stmt.XPATH]) continue if cmd == Cmd.CONSTANT: elt.text = doc[Stmt.VALUE] continue text = row[title] if Stmt.REQUIRED in doc and not text: print(f'*** Required column “{title}” is missing from' f' {accnum}. Object excluded.') emit = False if cmd == Cmd.ITEMS: create_items(doc, elt, template, text) else: elt.text = text if Stmt.DATE in doc: # Only britishdate supported now try: elt.text, _, _ = modesdatefrombritishdate(elt.text) # print(type(elt.text)) except ValueError: elt.text = 'unknown' if emit: nrows += 1 outfile.write(ET.tostring(template)) if not _args.noprolog: outfile.write(b'</Interchange>')