def merge_cmd(args): """Merge counts from one or more inputs into a new/existing collection.""" cdb = build_card_db(args.data_path, args.include_online_only) coll_serializer = get_serializer(cdb, args.dialect, args.collection) print_counts = counts.new_print_counts() if os.path.exists(args.collection): print("Reading counts from " + args.collection) print_counts = coll_serializer.read(args.collection) for import_file in args.imports: input_serializer = get_serializer(cdb, args.dialect, import_file) print("Merging counts from " + import_file) print_counts = counts.merge_print_counts( print_counts, input_serializer.read(import_file)) write_file(coll_serializer, print_counts, args.collection)
def read(self, filename: str): """Read print counts from an xlsx file.""" workbook = openpyxl.load_workbook(filename=filename, read_only=True) # pylint: disable=redefined-variable-type print_counts = {} for sheet in workbook.worksheets: if sheet.title not in self.cdb.code_to_card_set: if sheet.title in {'Sets', 'All Sets', 'All Cards'}: continue raise interface.DeserializationError( 'No known set with code {}'.format(sheet.title)) print_counts = counts.merge_print_counts( print_counts, counts.aggregate_print_counts( self.cdb, counts_from_sheet(sheet), strict=True)) return print_counts
def read(self, filename: str): """Read print counts from an xlsx file.""" workbook = openpyxl.load_workbook(filename=filename, read_only=True) print_counts = {} for sheet in workbook.worksheets: if sheet.title not in self.cdb.code_to_card_set: if sheet.title in {"Sets", "All Sets", "All Cards"}: continue raise interface.DeserializationError( "No known set with code {}".format(sheet.title)) print_counts = counts.merge_print_counts( print_counts, counts.aggregate_print_counts(self.cdb, counts_from_sheet(sheet), strict=True), ) return print_counts
def test_merge_print_counts(in_print_counts, out_print_counts): assert counts.merge_print_counts(*in_print_counts) == out_print_counts