diff options
author | Michał Klichowicz <emkael@tlen.pl> | 2023-10-05 22:49:59 +0200 |
---|---|---|
committer | Michał Klichowicz <emkael@tlen.pl> | 2023-10-05 22:49:59 +0200 |
commit | b84d880f5e4c0a0395630b24a42980758d912024 (patch) | |
tree | b48a65e67e816f27812228ace9c67017d0c77a62 /src | |
parent | 89c6d4555b3631fe0ca41d11a6e6842bc8c27c66 (diff) |
Config option for reading lineups from specific board number
Diffstat (limited to 'src')
-rw-r--r-- | src/bcdd/PBNBoard.py | 4 | ||||
-rw-r--r-- | src/main.py | 24 |
2 files changed, 19 insertions, 9 deletions
diff --git a/src/bcdd/PBNBoard.py b/src/bcdd/PBNBoard.py index e76252d..eb7ad2d 100644 --- a/src/bcdd/PBNBoard.py +++ b/src/bcdd/PBNBoard.py @@ -40,10 +40,12 @@ class PBNBoard(object): return True return False - def get_field(self, key): + def get_field(self, key, default=None): for field in self.fields: if key == field.key: return field.value + if default is not None: + return default raise FieldNotFoundException(key + ' field not found') def delete_field(self, key): diff --git a/src/main.py b/src/main.py index 32cd135..c4784e7 100644 --- a/src/main.py +++ b/src/main.py @@ -67,24 +67,32 @@ def get_round_lineup(db, round_no, segment_no): return round_lineup -def get_pbn_lineups(pbn, round_no): +def get_pbn_lineups(pbn, round_no, board_no=None): tables = {} for b in pbn.boards: if b.has_field('Round'): if b.get_field('Round') == str(round_no): - table = b.get_field('Table') - if table not in tables: - tables[table] = {} - tables[table][b.get_field('Room')] = [ - [b.get_field('North'), b.get_field('South')], - [b.get_field('East'), b.get_field('West')] + if not board_no or (str(board_no) == b.get_field('Board')): + table = b.get_field('Table') + if table not in tables: + tables[table] = {} + if board_no: + logging.info('Fetching lineups from board no %d, table %s %s', board_no, table, b.get_field('Room')) + tables[table][b.get_field('Room')] = [ + [b.get_field('North', ''), b.get_field('South', '')], + [b.get_field('East', ''), b.get_field('West', '')] ] return tables def fetch_lineups(pbn, db, settings): rosters = get_team_rosters(db) - tables = get_pbn_lineups(pbn, settings['pbn_round']) + lineup_board_no = settings.get('lineup_board_no', None) + if lineup_board_no is None: + board_mapping = get_board_mapping(db, settings['teamy_round'], settings['teamy_segment']) + lineup_board_no = list(board_mapping.keys())[list(board_mapping.values()).index(1)] + logging.info('No lineup board number specified in config, reverting to first board of segment: %d', lineup_board_no) + tables = get_pbn_lineups(pbn, settings['pbn_round'], lineup_board_no) round_lineup = get_round_lineup(db, settings['teamy_round'], settings['teamy_segment']) for t, rooms in tables.items(): |