Skip to content

Commit

Permalink
added missing src/main_json_generator.py
Browse files Browse the repository at this point in the history
  • Loading branch information
danellecline committed Mar 2, 2024
1 parent e77b298 commit fb2e6c7
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/main_json_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from datetime import datetime
from pathlib import Path

from src.json_generator.gen_nrs import NRSMetadataGenerator
from src.json_generator.gen_iclisten import IcListenMetadataGenerator
from src.json_generator.gen_soundtrap import SoundTrapMetadataGenerator
from src.main_json_generator_args import parse_arguments

# Some imports, in particular involving data processing, cause a delay that is
# noticeable when just running the --help option. We get around this issue by
# postponing the imports until actually needed. See the main() function.


def main(opts):
# pylint: disable=import-outside-toplevel
import logging
from src.logging_helper import create_logger

logger = create_logger(
log_filename_and_level=(
f"{opts.output_dir}/{opts.recorder}{opts.start}_{opts.end}.log",
logging.INFO,
),
console_level=logging.INFO,
)

log_dir = Path(opts.output_dir)
json_dir = Path(opts.json_base_dir)
log_dir.mkdir(exist_ok=True, parents=True)
json_dir.mkdir(exist_ok=True, parents=True)
start = datetime.strptime(opts.start, '%Y%m%d')
end = datetime.strptime(opts.end, '%Y%m%d')

try:
if opts.recorder == 'NRS':
generator = NRSMetadataGenerator(pbp_logger=logger,
uri=opts.uri,
json_base_dir=json_dir.as_posix(),
prefix=opts.prefix,
start=start,
end=end)
generator.run()
if opts.recorder == 'ICLISTEN':
generator = IcListenMetadataGenerator(pbp_logger=logger,
uri=opts.uri,
json_base_dir=json_dir.as_posix(),
prefix=opts.prefix,
start=start,
end=end)
generator.run()
# TODO: add multiprocessing here for speed-up
if opts.recorder == 'SOUNDTRAP':
generator = SoundTrapMetadataGenerator(pbp_logger=logger,
uri=opts.uri,
json_base_dir=json_dir.as_posix(),
prefix=opts.prefix,
start=start,
end=end)
generator.run()
except KeyboardInterrupt:
logger.info("INTERRUPTED")


if __name__ == "__main__":
main(parse_arguments())

0 comments on commit fb2e6c7

Please sign in to comment.