Add mega data file for functions API

This commit is contained in:
Xevion
2022-05-23 13:18:02 -05:00
parent 41ac4e46ba
commit d5a8b6d892
2 changed files with 12 additions and 1 deletions

View File

@@ -635,8 +635,9 @@ def images() -> None:
@build.command('app') @build.command('app')
@click.option('--path', type=str, default=BUILD_DIR, help='The output path for the application data files.') @click.option('--path', type=str, default=BUILD_DIR, help='The output path for the application data files.')
@click.option('--mega', type=click.Path(file_okay=False, exists=True), default=None, help='The output path for the "mega episode file".')
@click.option('--make-dir', is_flag=True, help='Create the output directory if it does not exist.') @click.option('--make-dir', is_flag=True, help='Create the output directory if it does not exist.')
def app(path: str, make_dir: bool) -> None: def app(path: str, mega: str, make_dir: bool) -> None:
"""Build the data files used by the application.""" """Build the data files used by the application."""
logger.debug('Build process called for "app".') logger.debug('Build process called for "app".')
logger.debug(f'Output Directory: "{os.path.relpath(path, os.getcwd())}"') logger.debug(f'Output Directory: "{os.path.relpath(path, os.getcwd())}"')
@@ -758,9 +759,13 @@ def app(path: str, make_dir: bool) -> None:
season, episode = episode_data['seasonNumber'], episode_data['episodeNumber'] season, episode = episode_data['seasonNumber'], episode_data['episodeNumber']
season_episode_data.append((season, episode, episode_data)) season_episode_data.append((season, episode, episode_data))
mega_file_data: List[List[Any]] = [[None for _ in range(count)] for count in EPISODE_COUNTS]
with progress: with progress:
for season, episode, episode_data in progress.track(season_episode_data, description='Saving episode data...', for season, episode, episode_data in progress.track(season_episode_data, description='Saving episode data...',
update_period=0.1): update_period=0.1):
mega_file_data[season - 1][episode - 1] = episode_data
season_directory = os.path.join(path, f'{season:02}') season_directory = os.path.join(path, f'{season:02}')
if not os.path.exists(season_directory): if not os.path.exists(season_directory):
os.makedirs(season_directory) os.makedirs(season_directory)
@@ -770,6 +775,11 @@ def app(path: str, make_dir: bool) -> None:
with open(episode_path, 'w') as episode_file: with open(episode_path, 'w') as episode_file:
json.dump(episode_data, episode_file) json.dump(episode_data, episode_file)
if mega is not None:
with open(os.path.join(mega, 'data.json'), 'w') as mega_file:
json.dump(mega_file_data, mega_file)
logger.debug('Mega data file written.')
episodes_path = os.path.join(path, 'episodes.json') episodes_path = os.path.join(path, 'episodes.json')
included: List[str] = ['characters', 'description', 'title', 'episodeNumber', 'seasonNumber'] included: List[str] = ['characters', 'description', 'title', 'episodeNumber', 'seasonNumber']
basic_episode_data = [[None for _ in range(count)] for count in EPISODE_COUNTS] basic_episode_data = [[None for _ in range(count)] for count in EPISODE_COUNTS]

1
functions/src/data.json Normal file
View File

File diff suppressed because one or more lines are too long