cuongnguyen910's picture
Upload folder using huggingface_hub
5120311 verified
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"
# http://10.9.2.151:31244/api/configserver/v1/configuration.yaml
# cấu hình file hosts ở thư mục C:\Windows\System32\drivers\etc như sau:
# 123.31.42.17 icomm-api-configserver
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)
# if response.status_code == 200:
# with open(path_save_cfg, "w+") as f:
# f.write(response.text)
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"]))