-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added missing src/main_json_generator.py
- Loading branch information
1 parent
e77b298
commit fb2e6c7
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |