-
Notifications
You must be signed in to change notification settings - Fork 4
/
util.py
26 lines (21 loc) · 897 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
excluded_prefixes = ('.', '_', '@')
known_countries = {'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE',
'ES', 'FR', 'GR', 'HR', 'IS', 'IT', 'LU', 'LV',
'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK'}
def walk_path(root_dir: str, country: str) -> list[str]:
files = []
country_dir = os.path.join(root_dir, country)
for dirpath, dirnames, filenames in os.walk(country_dir):
dirnames[:] = [dirname for dirname in dirnames if not dirname.startswith(excluded_prefixes)]
for filename in filenames:
files.append(os.path.join(dirpath, filename))
return files
def list_country_directories(root_directory: str):
dirs = []
for a, dirnames, b in os.walk(root_directory):
for directory in dirnames:
if len(directory) == 2:
dirs.append(directory)
break
return dirs