def do_genus(filename): """ Convert genus.txt """ from bauble.plugins.plants import Genus, GenusNote reader = UnicodeReader(open(filename)) genus_filename = os.path.join(dst_path, 'genus.txt') genus_writer = UnicodeWriter(open(genus_filename, "wb")) genus_columns = ['id', 'genus', 'hybrid', 'author', 'qualifier', 'family_id', '_created', '_last_updated'] genus_writer.writerow(genus_columns) note_filename = os.path.join(dst_path, 'genus_note.txt') note_writer = NoteWriter(note_filename, 'genus_id') for line in reader: note = line.pop('notes') genus_writer.writerow([line['id'], line['genus'], line['hybrid'], line['author'], line['qualifier'], line['family_id'], line['_created'], line['_last_updated']]) if note: note_writer.write(note, line['id'])
def do_genus(filename): """ Convert genus.txt """ from bauble.plugins.plants import Genus, GenusNote reader = UnicodeReader(open(filename)) genus_filename = os.path.join(dst_path, 'genus.txt') genus_writer = UnicodeWriter(open(genus_filename, "wb")) genus_columns = ['id', 'genus', 'hybrid', 'author', 'qualifier', 'family_id', '_created', '_last_updated'] genus_writer.writerow(genus_columns) note_filename = os.path.join(dst_path, 'genus_note.txt') note_writer = NoteWriter(note_filename, 'genus_id') for line in reader: note = line.pop('notes') genus_writer.writerow([line['id'], line['genus'], line['hybrid'], line['author'], line['qualifier'], line['family_id'], line['_created'], line['_last_updated']]) if note: note_writer.write(note, line['id'])
def do_species(filename): """ Convert species.txt """ from bauble.plugins.plants import Species, SpeciesNote reader = UnicodeReader(open(filename)) species_filename = os.path.join(dst_path, 'species.txt') species_writer = UnicodeWriter(open(species_filename, "wb")) species_columns = ['id', 'sp', 'sp2', 'sp_author', 'hybrid', 'sp_qual', 'cv_group', 'trade_name', 'infrasp1', 'infrasp1_rank', 'infrasp1_author', 'infrasp2', 'infrasp2_rank', 'infrasp2_author', 'infrasp3', 'infrasp3_rank', 'infrasp3_author', 'infrasp4', 'infrasp4_rank', 'infrasp4_author', 'genus_id', 'label_distribution', 'habit_id', 'flower_color_id', 'awards', '_created', '_last_updated'] species_writer.writerow(species_columns) note_filename = os.path.join(dst_path, 'species_note.txt') note_writer = NoteWriter(note_filename, 'species_id') for line in reader: # in bauble 0.9 if sp_hybrid was not None then the infrasp held sp2 hybrid = False if line['sp_hybrid']: hybrid = True if line['infrasp_rank'] or line['infrasp_author']: print '**', line['sp'], line['infrasp'], line['infrasp_rank'], \ line['infrasp_author'] sp2 = line['infrasp'] infrasp1 = None else: sp2 = None infrasp1 = line['infrasp'] species_writer.writerow([line['id'], line['sp'], sp2, line['sp_author'], hybrid, line['sp_qual'], line['cv_group'], line['trade_name'], infrasp1, line['infrasp_rank'], line['infrasp_author'], None, None, None, # infrasp2 None, None, None, # infrasp3 None, None, None, # infrasp4 line['genus_id'], None, # label_distribution None, # habit_id, None, # flower_color_id None, # awards line['_created'], line['_last_updated']]) note = line.pop('notes') if note: note_writer.write(note, line['id'])
def do_species(filename): """ Convert species.txt """ from bauble.plugins.plants import Species, SpeciesNote reader = UnicodeReader(open(filename)) species_filename = os.path.join(dst_path, 'species.txt') species_writer = UnicodeWriter(open(species_filename, "wb")) species_columns = ['id', 'sp', 'sp2', 'sp_author', 'hybrid', 'sp_qual', 'cv_group', 'trade_name', 'infrasp1', 'infrasp1_rank', 'infrasp1_author', 'infrasp2', 'infrasp2_rank', 'infrasp2_author', 'infrasp3', 'infrasp3_rank', 'infrasp3_author', 'infrasp4', 'infrasp4_rank', 'infrasp4_author', 'genus_id', 'label_distribution', 'habit_id', 'flower_color_id', 'awards', '_created', '_last_updated'] species_writer.writerow(species_columns) note_filename = os.path.join(dst_path, 'species_note.txt') note_writer = NoteWriter(note_filename, 'species_id') for line in reader: # in bauble 0.9 if sp_hybrid was not None then the infrasp held sp2 hybrid = False if line['sp_hybrid']: hybrid = True if line['infrasp_rank'] or line['infrasp_author']: print '**', line['sp'], line['infrasp'], line['infrasp_rank'], \ line['infrasp_author'] sp2 = line['infrasp'] infrasp1 = None else: sp2 = None infrasp1 = line['infrasp'] species_writer.writerow([line['id'], line['sp'], sp2, line['sp_author'], hybrid, line['sp_qual'], line['cv_group'], line['trade_name'], infrasp1, line['infrasp_rank'], line['infrasp_author'], None, None, None, # infrasp2 None, None, None, # infrasp3 None, None, None, # infrasp4 line['genus_id'], None, # label_distribution None, # habit_id, None, # flower_color_id None, # awards line['_created'], line['_last_updated']]) note = line.pop('notes') if note: note_writer.write(note, line['id'])
def do_family(filename): """ Convert the family.txt """ reader = UnicodeReader(open(filename)) family_filename = os.path.join(dst_path, 'family.txt') family_writer = UnicodeWriter(open(family_filename, "wb")) family_columns = ['id', 'epithet', 'hybrid_marker', 'author', 'aggregate', '_created', '_last_updated'] family_writer.writerow(family_columns) for line in reader: family_writer.writerow([line['id'], line['family'], '', '', '', line['_created'], line['_last_updated']]) print 'done'
def do_family(filename): """ Convert the family.txt """ reader = UnicodeReader(open(filename)) family_filename = os.path.join(dst_path, 'family.txt') family_writer = UnicodeWriter(open(family_filename, "wb")) family_columns = [ 'id', 'epithet', 'hybrid_marker', 'author', 'aggregate', '_created', '_last_updated' ] family_writer.writerow(family_columns) for line in reader: family_writer.writerow([ line['id'], line['family'], '', '', '', line['_created'], line['_last_updated'] ]) print 'done'
def do_family(filename): """ Convert the family.txt """ from bauble.plugins.plants import Family, FamilyNote, FamilySynonym reader = UnicodeReader(open(filename)) family_filename = os.path.join(dst_path, 'family.txt') family_writer = UnicodeWriter(open(family_filename, "wb")) family_columns = ['id', 'family', 'qualifier', '_created', '_last_updated'] family_writer.writerow(family_columns) note_filename = os.path.join(dst_path, 'family_note.txt') note_writer = NoteWriter(note_filename, 'family_id') for line in reader: note = line.pop('notes') family_writer.writerow([line['id'], line['family'], line['qualifier'], line['_created'], line['_last_updated']]) if note: note_writer.write(note, line['id'])
def do_family(filename): """ Convert the family.txt """ from bauble.plugins.plants import Family, FamilyNote, FamilySynonym reader = UnicodeReader(open(filename)) family_filename = os.path.join(dst_path, 'family.txt') family_writer = UnicodeWriter(open(family_filename, "wb")) family_columns = ['id', 'family', 'qualifier', '_created', '_last_updated'] family_writer.writerow(family_columns) note_filename = os.path.join(dst_path, 'family_note.txt') note_writer = NoteWriter(note_filename, 'family_id') for line in reader: note = line.pop('notes') family_writer.writerow([line['id'], line['family'], line['qualifier'], line['_created'], line['_last_updated']]) if note: note_writer.write(note, line['id'])
def do_genus(filename): """ Convert genus.txt """ reader = UnicodeReader(open(filename)) genus_filename = os.path.join(dst_path, 'genus.txt') genus_writer = UnicodeWriter(open(genus_filename, "wb")) genus_columns = [ 'id', 'epithet', 'hybrid_marker', 'author', 'aggregate', 'family_id', '_created', '_last_updated' ] genus_writer.writerow(genus_columns) for line in reader: genus_writer.writerow([ line['id'], line['genus'], '', line['author'], line['qualifier'], line['family_id'], line['_created'], line['_last_updated'] ]) print 'done'
def do_genus(filename): """ Convert genus.txt """ reader = UnicodeReader(open(filename)) genus_filename = os.path.join(dst_path, 'genus.txt') genus_writer = UnicodeWriter(open(genus_filename, "wb")) genus_columns = [ 'id', 'epithet', 'hybrid_marker', 'author', 'aggregate', 'family_id', '_created', '_last_updated'] genus_writer.writerow(genus_columns) for line in reader: genus_writer.writerow( [line['id'], line['genus'], '', line['author'], line['qualifier'], line['family_id'], line['_created'], line['_last_updated']]) print 'done'
def do_species(filename): """ Convert species.txt """ reader = UnicodeReader(open(filename)) species_filename = os.path.join(dst_path, 'species.txt') writer = UnicodeWriter(open(species_filename, "wb")) columns = [ 'id', 'epithet', 'hybrid_marker', 'author', 'aggregate', 'cv_group', 'trade_name', 'infrasp1', 'infrasp1_rank', 'infrasp1_author', 'infrasp2', 'infrasp2_rank', 'infrasp2_author', 'infrasp3', 'infrasp3_rank', 'infrasp3_author', 'infrasp4', 'infrasp4_rank', 'infrasp4_author', 'genus_id', 'label_distribution', 'bc_distribution', 'habit_id', 'flower_color_id', 'awards', '_created', '_last_updated' ] writer.writerow(columns) post_process_hyop = [] for line in reader: line = dict(line) if line['sp'] and (line['sp'].find(u'×') > 0): line['hybrid_marker'] = 'H' line['epithet'] = '' post_process_hyop.append(dict(line)) else: line['hybrid_marker'] = (line['hybrid'] == 'True') and u'×' or '' line['epithet'] = line['sp'] line['author'] = line['sp_author'] line['aggregate'] = line['sp_qual'] writer.writerow([line[k] for k in columns]) hybrid_operand = os.path.join(dst_path, 'hybrid_operands.txt') hyop_columns = ['child_id', 'parent_id', 'role'] hyop_writer = create_writer(hybrid_operand, hyop_columns) if post_process_hyop: print post_process_hyop print 'done'
def do_species(filename): """ Convert species.txt """ reader = UnicodeReader(open(filename)) species_filename = os.path.join(dst_path, 'species.txt') writer = UnicodeWriter(open(species_filename, "wb")) columns = [ 'id', 'epithet', 'hybrid_marker', 'author', 'aggregate', 'cv_group', 'trade_name', 'infrasp1', 'infrasp1_rank', 'infrasp1_author', 'infrasp2', 'infrasp2_rank', 'infrasp2_author', 'infrasp3', 'infrasp3_rank', 'infrasp3_author', 'infrasp4', 'infrasp4_rank', 'infrasp4_author', 'genus_id', 'label_distribution', 'bc_distribution', 'habit_id', 'flower_color_id', 'awards', '_created', '_last_updated'] writer.writerow(columns) post_process_hyop = [] for line in reader: line = dict(line) if line['sp'] and (line['sp'].find(u'×') > 0): line['hybrid_marker'] = 'H' line['epithet'] = '' post_process_hyop.append(dict(line)) else: line['hybrid_marker'] = (line['hybrid'] == 'True') and u'×' or '' line['epithet'] = line['sp'] line['author'] = line['sp_author'] line['aggregate'] = line['sp_qual'] writer.writerow([line[k] for k in columns]) hybrid_operand = os.path.join(dst_path, 'hybrid_operands.txt') hyop_columns = ['child_id', 'parent_id', 'role'] hyop_writer = create_writer(hybrid_operand, hyop_columns) if post_process_hyop: print post_process_hyop print 'done'
def create_writer(filename, columns): writer = UnicodeWriter(open(filename, "a+b")) writer.writerow(columns) return writer
def create_writer(filename, columns): writer = UnicodeWriter(open(filename, "a+b")) writer.writerow(columns) return writer