Skip to content

Commit

Permalink
feat: load_domjudge_api
Browse files Browse the repository at this point in the history
Signed-off-by: Dup4 <lyuzhi.pan@gmail.com>
  • Loading branch information
Dup4 committed May 23, 2023
1 parent 4f19a4b commit 2c1d64e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion domjudge_utility/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def __init__(self, config: DumpConfig = None):
self.groups_dict = None
self.teams_dict = None

self.logger = None

def output_to_file(self, filepath: str, data: str, if_not_exists=False):
dir_name = os.path.join(self.config.saved_dir, filepath)

Expand All @@ -72,6 +74,9 @@ def output_to_file(self, filepath: str, data: str, if_not_exists=False):
f.write(data)

def init_logging(self):
if self.logger is not None:
return

self.logger = logging.getLogger(__name__)
self.logger.setLevel(logging.INFO)

Expand Down Expand Up @@ -113,7 +118,7 @@ def request_json(self, endpoint, params={}):

return content
else:
file_path = os.path.join(self.config.base_file_path, endpoint)
file_path = os.path.join(self.config.base_file_path, "domjudge", "api", endpoint)
self.logger.info('GET {}'.format(file_path))
with open(file_path, 'r') as f:
return f.read()
Expand Down Expand Up @@ -636,3 +641,10 @@ def dump(self):
self.dump_source_code()
self.dump_images()
self.dump_3rd_data()

def load_domjudge_api(self):
self.config.exported_data.domjudge_api = False

self.init_logging()
self.dump_domjudge_api()
self.process_domjudge_raw_data()
2 changes: 1 addition & 1 deletion domjudge_utility/dump_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, exported_data_dict):
self.scoreboard_excel_data = DumpConfig.get_config_with_default_value(
exported_data_dict, 'scoreboard_excel_data', False)

def __init__(self, config_dict):
def __init__(self, config_dict={}):
self.base_file_path = self.get_config_with_default_value(
config_dict, 'base_file_path', '')

Expand Down

0 comments on commit 2c1d64e

Please sign in to comment.