From eee3954a793379611684ac01b1a4f217a16048d7 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 21 May 2019 00:46:58 +0200 Subject: Fallback if PBN has no dealer/vulnerability data --- dealconvert/formats/pbn.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'dealconvert/formats/pbn.py') diff --git a/dealconvert/formats/pbn.py b/dealconvert/formats/pbn.py index e3fc384..f1d3042 100644 --- a/dealconvert/formats/pbn.py +++ b/dealconvert/formats/pbn.py @@ -68,10 +68,16 @@ class PBNFormat(DealFormat): 'E': dto.POSITION_EAST, 'S': dto.POSITION_SOUTH, 'W': dto.POSITION_WEST} - deal_dto.dealer = dealers[deal_obj.get_field('Dealer')] - vulnerability = deal_obj.get_field('Vulnerable') - for pair in deal_dto.vulnerable: - deal_dto.vulnerable[pair] = vulnerability in [pair, 'All'] + if deal_obj.has_field('Dealer'): + deal_dto.dealer = dealers[deal_obj.get_field('Dealer')] + else: + deal_dto.dealer = deal_dto.get_dealer(deal_dto.number) + if deal_obj.has_field('Vulnerable'): + vulnerability = deal_obj.get_field('Vulnerable') + for pair in deal_dto.vulnerable: + deal_dto.vulnerable[pair] = vulnerability in [pair, 'All'] + else: + deal_dto.vulnerable = deal_dto.get_vulnerability(deal_dto.number) deal_parts = deal_obj.get_field('Deal').split(':') dealer = dealers[deal_parts[0]] hands = deal_parts[1].split(' ') @@ -81,8 +87,8 @@ class PBNFormat(DealFormat): result.append(deal_dto) return result - def output_content(self, out_file, deal): - for board in deal: + def output_content(self, out_file, dealset): + for board in dealset: out_file.write('[Event "%s"]\r\n' % (board.event)) out_file.write('[Board "%d"]\r\n' % (board.number)) out_file.write('[Dealer "%s"]\r\n' % ( -- cgit v1.2.3