Commit 5668bd1b authored by Bruno Duyé's avatar Bruno Duyé

Add --series option

parent 29529b8d
Pipeline #103963 failed with stage
in 4 minutes and 50 seconds
......@@ -182,8 +182,20 @@ def load_series_xml_file(xml_file: Path):
def generate_series(ds_dir, source_dir, dimension_codes):
""" Browse source dir form XML file, extract content and save series in dataset dir """
def get_series_code_from_filename(filename):
""" 'bbk01.xu4205.xml' => 'xu4205'
"""
match = re.search(r'.+?\.(.+)\.xml', filename)
return match.group(1)
series_info_list = []
for xml_file in source_dir.glob('*.xml'):
series_code_from_filename = get_series_code_from_filename(xml_file.name)
if args.series and not series_code_from_filename in args.series:
log.debug('Skipping {!r} series due to "--series" option'.format(series_code_from_filename))
continue
xml_info = load_series_xml_file(xml_file)
ts_code = xml_info['code']
......@@ -414,8 +426,12 @@ def main():
parser.add_argument('source_dir', type=Path, help='path of source directory')
parser.add_argument('target_dir', type=Path, help='path of target directory')
parser.add_argument('--log', default='WARNING', help='level of logging messages')
parser.add_argument('--datasets', nargs='+', metavar='DATASET_CODE', help='convert only the given datasets (datasets codes, space separated)')
parser.add_argument('--datasets', nargs='+', metavar='DATASET_CODE',
help='only convert given datasets (datasets codes, space separated)')
parser.add_argument('--series', nargs='+', metavar='SERIES_CODE',
help='only convert given series (series codes, space separated)')
parser.add_argument('--skip-category-tree', action='store_true', help='do not generate category tree')
global args
args = parser.parse_args()
numeric_level = getattr(logging, args.log.upper(), None)
......@@ -445,7 +461,7 @@ def main():
for ds_code in sorted([d.name for d in time_series_dir.iterdir() if d.is_dir()]):
if args.datasets and not ds_code in args.datasets:
log.debug('Skipping {!r} dataset due to "--datasets" option')
log.debug('Skipping {!r} dataset due to "--datasets" option'.format(ds_code))
continue
log.info('Generating [%s] dataset', ds_code)
ds_source_dir = time_series_dir / ds_code
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment