summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2024-05-06 11:06:24 +0200
committeremkael <emkael@tlen.pl>2024-05-06 11:06:24 +0200
commitfa336220a6c1488d11d8ce3adef477fb79f70347 (patch)
tree9393544528f0754d27eef2c7084e2fc82f1beb88
parent53ad264f0d2fad636ab5d0ae629837f2f25999dc (diff)
TC board scraper ignoring non-loaded records
-rw-r--r--boards/scrapers/tournamentcalculator/scrape.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/boards/scrapers/tournamentcalculator/scrape.py b/boards/scrapers/tournamentcalculator/scrape.py
index 1d79d8a..f61506b 100644
--- a/boards/scrapers/tournamentcalculator/scrape.py
+++ b/boards/scrapers/tournamentcalculator/scrape.py
@@ -24,11 +24,12 @@ prev_board_number = 0
for board in sorted(board_numbers):
board_data = get_json_content('p%d.json' % board)['ScoringGroups'][scoring_group-1]['Distribution']
- if board_data['_numberAsPlayed'] < prev_board_number:
- board_sets.append(current_board_set)
- current_board_set = []
- current_board_set.append(board_data)
- prev_board_number = board_data['_numberAsPlayed']
+ if board_data:
+ if board_data['_numberAsPlayed'] < prev_board_number:
+ board_sets.append(current_board_set)
+ current_board_set = []
+ current_board_set.append(board_data)
+ prev_board_number = board_data['_numberAsPlayed']
board_sets.append(current_board_set)
for idx, board_set in enumerate(board_sets):
@@ -38,14 +39,15 @@ for idx, board_set in enumerate(board_sets):
output_file.write('[Generator "TC-scraper"]\n')
output_file.write('[Event "%s %d/%d"]\n' % (tournament_name, idx+1, len(board_sets)))
for board in board_set:
- board_number = board['_numberAsPlayed']
- board_record = []
- for hand in ['N', 'E', 'S', 'W']:
- hand_record = []
- for suit in ['Spades', 'Hearts', 'Diamonds', 'Clubs']:
- hand_record.append(board['_handRecord']['Hand%s' % (hand)][suit])
- board_record.append('.'.join(hand_record).replace('10', 'T'))
- output_file.write('[Board "%d"]\n' % (board_number))
- output_file.write('[Dealer "%s"]\n' % (['W', 'N', 'E', 'S'][board_number % 4]))
- output_file.write('[Deal "N:%s"]\n' % (' '.join(board_record)))
- output_file.write('\n')
+ if board:
+ board_number = board['_numberAsPlayed']
+ board_record = []
+ for hand in ['N', 'E', 'S', 'W']:
+ hand_record = []
+ for suit in ['Spades', 'Hearts', 'Diamonds', 'Clubs']:
+ hand_record.append(board['_handRecord']['Hand%s' % (hand)][suit])
+ board_record.append('.'.join(hand_record).replace('10', 'T'))
+ output_file.write('[Board "%d"]\n' % (board_number))
+ output_file.write('[Dealer "%s"]\n' % (['W', 'N', 'E', 'S'][board_number % 4]))
+ output_file.write('[Deal "N:%s"]\n' % (' '.join(board_record)))
+ output_file.write('\n')