# -*-coding:utf-8-*-
import sys
import requests
import io
import os
import chardet

privacy_url=sys.argv[1]

#是否更新本地文件
path = "../../../app/src/main/assets/web/".replace("/",os.path.sep)
if not os.path.exists(path):
    os.makedirs(path)
resp = requests.get(privacy_url);
content = resp.text
encode = chardet.detect(resp.content)['encoding']
with io.open(path+"privacy.html", "w+", encoding=encode) as fout:
    fout.write(content)
    print("本地协议已更新！" + privacy_url)


ksp_url=privacy_url.replace(".html","Ksp.html")
resp = requests.get(ksp_url)
content = resp.text
encode = chardet.detect(resp.content)['encoding']
if "<Code>NoSuchKey</Code>" not in content:
    with io.open(path+"privacyKsp.html", "w+", encoding=encode) as fout:
        fout.write(content)
        print("本地KSP协议已更新！" + ksp_url)
