-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (41 loc) · 1.7 KB
/
main.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import json
from core.config_merger import merge_configs
from core.requester import getWMSRCapabilities, getWMSVCapabilities, getWMTSCapabilities, getWFSCapabilities
from core.vectortiles_parser import parseVectorTiles
from core.wms_parser import parseWMS
from core.wmts_parser import parseWMTS
from core.wfs_parser import parseWFS
from core.key_resource_lister import createKeyServiceLayersFile
def main(keys, referer=""):
createKeyServiceLayersFile()
if not isinstance(keys, list):
keys = [keys]
keys = filter(lambda x: x != "", keys)
list_configs = [
config for key in keys
for config in [
parseWMTS(getWMTSCapabilities(key, referer), key),
parseWMS(getWMSRCapabilities(key, referer), key),
parseWMS(getWMSVCapabilities(key, referer), key),
parseWFS(getWFSCapabilities(key, referer)[0], key, getWFSCapabilities(key, referer)[1]),
parseVectorTiles(key)
]
]
list_configs = [config for config in list_configs if isinstance(config, dict)]
try:
merged_config = merge_configs(list_configs)
except IndexError:
return "No key provided was valid"
return json.dumps(merged_config, indent=2, ensure_ascii=False)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("keys", nargs="+")
parser.add_argument("--referer", required=False, default="")
keys = parser.parse_args().keys
referer = parser.parse_args().referer
config_name = keys[0]
if len(keys) > 1:
config_name = "custom"
with open("dist/{}Config.json".format(config_name), "w", encoding="utf-8") as file:
file.writelines(main(keys, referer))