diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bidding_data.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/bidding_data.py b/src/bidding_data.py index ae789f1..98762b6 100644 --- a/src/bidding_data.py +++ b/src/bidding_data.py @@ -3,7 +3,7 @@ import glob import re import pypyodbc -from os import path +from os import path, remove from bs4 import BeautifulSoup as bs4 @@ -148,6 +148,9 @@ class JFRBidding: # BWS number -> JFR number mapping __board_number_mapping = {} + # all generated bidding table files, for cleanup purposes + __bidding_files = [] + def __init__(self, bws_file, file_prefix): with pypyodbc.win_connect_mdb(bws_file) as connection: cursor = connection.cursor() @@ -198,6 +201,7 @@ class JFRBidding: self.__get_bidding_file_output_path( self.__board_number_mapping[board_no], round_no, table_no) + self.__bidding_files.append(bidding_fpath) with file(bidding_fpath, 'w') as bidding_file: bidding_file.write( self.__format_bidding(bidding_table)) @@ -255,10 +259,14 @@ class JFRBidding: bidding_link = board_text_content.new_tag( 'a', href='#', **{'class': 'biddingLink'}) bidding_link.string = ' ' + bidding_path = self.__get_bidding_file_output_path( + int(file_number, 10), + pair_numbers=pair_numbers) bidding_link['data-bidding-link'] = path.basename( - self.__get_bidding_file_output_path( - int(file_number, 10), - pair_numbers=pair_numbers)) + bidding_path) + if bidding_path in self.__bidding_files: + del self.__bidding_files[ + self.__bidding_files.index(bidding_path)] # only append link if we've got bidding data if path.isfile(path.join( path.dirname(self.__tournament_prefix), @@ -271,6 +279,8 @@ class JFRBidding: board_text.write(board_text_content.table.prettify( 'iso-8859-2', formatter='html')) board_text.truncate() + for unused_file in self.__bidding_files: + remove(unused_file) if __name__ == '__main__': import argparse |