diff options
Diffstat (limited to 'boards/scrapers/tournamentcalculator/scrape.py')
-rw-r--r-- | boards/scrapers/tournamentcalculator/scrape.py | 34 |
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') |