Esempio n. 1
0
def update_readme(file, data):
    insert = "---start---\n\n" + _local_time_format + "\n\n" + data + "\n---end---"
    # 获取README.md内容
    with open(file, 'r', encoding='utf-8') as f:
        content = f.read()
    new_content = re.sub(r'---start---(.|\n)*?---end---', insert, content, 1)

    with open(file, 'w', encoding='utf-8', newline="\n") as f:
        f.write(new_content)

    fnLog("更新 README 成功")

    return True
Esempio n. 2
0
def for_instances(host_list, route_info):
    (title, path) = (route_info["title"], route_info["path"])
    fnLog(title)
    fnLog(path)
    name = path.replace("/", "_")
    for host in host_list:
        url = "%s%s" % (host, path)
        if (get_xml(url, name)):
            fnLog("抓取成功")
            break
        fnLog("---")
    return (title, path, name)
Esempio n. 3
0
def get_xml(url, name):
    rlt = False
    xml_file = os.path.join(os.getcwd(), "xml/%s.xml" % name)
    fnLog(url)
    try:
        r = requests.get(url, timeout=5)
        fnLog(r.status_code)
        if (r.status_code == 200):
            with open(xml_file, 'w', encoding='utf-8') as f:
                f.write(r.text)
            rlt = True
    except:
        fnLog("err")
    return rlt
Esempio n. 4
0
def main():
    global _opml, _baseUrl
    _opml = opml()
    # 配置路径
    _confg_json = os.path.join(os.getcwd(), "config.json")
    _config_yml = os.path.join(os.getcwd(), "config.yml")

    # 配置读取
    _confg_data = read_json(_confg_json)
    if not any(_confg_data):
        _confg_data = read_yml(_config_yml)
    # print(_confg_data)
    _routes = _confg_data["routes"]
    _instances = _confg_data["instances"]

    if "baseUrl" in _confg_data:
        _baseUrl = _confg_data["baseUrl"]
    try:
        if (os.environ["GITHUB_REPOSITORY"]):
            fnBug(os.environ["GITHUB_REPOSITORY"])
            _baseUrl = "https://raw.githubusercontent.com/%s/main" % os.environ[
                "GITHUB_REPOSITORY"]
    except:
        fnLog()

    print("-----")

    # README.md
    _readme_file = os.path.join(os.getcwd(), "README.md")

    _readme_data = for_routes(_routes, _instances)

    update_readme(_readme_file, _readme_data)

    # opml 存放
    _out_opml = os.path.join(os.getcwd(), "rss.opml")
    _opml.saveToFile(_out_opml)
    fnLog(["更新 OPML 成功", _out_opml])
    fnLog()
Esempio n. 5
0
    try:
        if (os.environ["GITHUB_REPOSITORY"]):
            fnBug(os.environ["GITHUB_REPOSITORY"])
            _baseUrl = "https://raw.githubusercontent.com/%s/main" % os.environ[
                "GITHUB_REPOSITORY"]
    except:
        fnLog()

    print("-----")

    # README.md
    _readme_file = os.path.join(os.getcwd(), "README.md")

    _readme_data = for_routes(_routes, _instances)

    update_readme(_readme_file, _readme_data)

    # opml 存放
    _out_opml = os.path.join(os.getcwd(), "rss.opml")
    _opml.saveToFile(_out_opml)
    fnLog(["更新 OPML 成功", _out_opml])
    fnLog()


# main

main()

fnLog("当前时间戳:%s, %s" % (_now, _local_time_format))
fnLog()