|
import requests
|
|
import json
|
|
import os
|
|
from yaml import load
|
|
try:
|
|
from yaml import CLoader as Loader, CDumper as Dumper
|
|
except ImportError:
|
|
from yaml import Loader, Dumper
|
|
|
|
|
|
URL_CFG = "http://icomm-api-configserver/api/configserver/v1/configuration.yaml"
|
|
|
|
|
|
|
|
|
|
AccessToken = "wbecrEfJk8F36y0WojqBQaqT28d6NaBnCLBgkoO2sCg3aNhYACkSxMNvWwlsAj5k"
|
|
Environment = "Production"
|
|
path_save_cfg = "config/cfg.yaml"
|
|
|
|
|
|
def get_config():
|
|
cfg = None
|
|
try:
|
|
payload = json.dumps({
|
|
"AccessToken": AccessToken,
|
|
"Environment": Environment
|
|
})
|
|
headers = {
|
|
'accept': 'text/plain',
|
|
'Content-Type': 'application/json-patch+json'
|
|
}
|
|
|
|
response = requests.request("POST", URL_CFG, headers=headers, data=payload)
|
|
|
|
|
|
|
|
except Exception as ve:
|
|
print(ve)
|
|
if os.path.exists(path_save_cfg):
|
|
with open(path_save_cfg) as f:
|
|
cfg = load(f, Loader)
|
|
return cfg
|
|
|
|
|
|
def parse_connection_string(str_cnn):
|
|
res = dict()
|
|
split_dt = str_cnn.split(";")
|
|
for c_sp in split_dt:
|
|
k, v = c_sp.split("=")
|
|
res[k.strip()] = v.replace("'", "").replace('"', '')
|
|
return res
|
|
|
|
|
|
if __name__ == '__main__':
|
|
cf = get_config()
|
|
print(cf)
|
|
print(parse_connection_string(cf["ConfigManager"]["ConnectionStrings"]["facebook_info"]["Value"])) |