diff --git a/README.md b/README.md index 58bffcf3b..3cb39a24c 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ 上面内容会自动定时更新,保证最新有效。数据更新时间:2021-05-31T12:58:34+08:00(内容无变动不会更新) + ### 2.1 手动方式 #### 2.1.1 修改 hosts 文件 hosts 文件在每个系统的位置不一,详情如下: diff --git a/README_template.md b/README_template.md index 6b05f495b..3321d1485 100644 --- a/README_template.md +++ b/README_template.md @@ -28,7 +28,11 @@ 上面内容会自动定时更新,保证最新有效。数据更新时间:{update_time}(内容无变动不会更新) +- 文件:`https://raw.fastgit.org/521xueweihan/GitHub520/main/hosts` +- JSON:`https://raw.fastgit.org/521xueweihan/GitHub520/main/hosts.json` + ### 2.1 手动方式 + #### 2.1.1 修改 hosts 文件 hosts 文件在每个系统的位置不一,详情如下: - Windows 系统:`C:\Windows\System32\drivers\etc\hosts` diff --git a/fetch_ips.py b/fetch_ips.py index 780727f38..fd2b51607 100644 --- a/fetch_ips.py +++ b/fetch_ips.py @@ -13,9 +13,8 @@ import traceback from datetime import datetime, timezone, timedelta from collections import Counter -from retry import retry - import requests +from retry import retry RAW_URL = [ "alive.github.com", @@ -65,8 +64,7 @@ def write_file(hosts_content: str, update_time: str): output_doc_file_path = os.path.join(os.path.dirname(__file__), "README.md") template_path = os.path.join(os.path.dirname(__file__), "README_template.md") - # 应该取消 write yaml file,改成 gitee gist 地址同步(国内访问流畅) - write_yaml_file(hosts_content) + write_host_file(hosts_content) with open(output_doc_file_path, "r") as old_readme_fb: old_content = old_readme_fb.read() old_hosts = old_content.split("```bash")[1].split("```")[0].strip() @@ -84,10 +82,16 @@ def write_file(hosts_content: str, update_time: str): return True -def write_yaml_file(hosts_content: str, ): - output_yaml_file_path = os.path.join(os.path.dirname(__file__), 'hosts') - with open(output_yaml_file_path, "w") as output_yaml_fb: - output_yaml_fb.write(hosts_content) +def write_host_file(hosts_content: str): + output_file_path = os.path.join(os.path.dirname(__file__), 'hosts') + with open(output_file_path, "w") as output_fb: + output_fb.write(hosts_content) + + +def write_json_file(hosts_dict: dict): + output_file_path = os.path.join(os.path.dirname(__file__), 'hosts.json') + with open(output_file_path, "w") as output_fb: + json.dump(hosts_dict, output_fb) def make_ipaddress_url(raw_url: str): @@ -151,10 +155,12 @@ def update_gitee_gist(session: requests.session, host_content): def main(): session = requests.session() content = "" + content_dict = {} for raw_url in RAW_URL: try: host_name, ip = get_ip(session, raw_url) content += ip.ljust(30) + host_name + "\n" + content_dict[ip] = host_name except Exception: continue @@ -165,10 +171,7 @@ def main(): hosts_content = HOSTS_TEMPLATE.format(content=content, update_time=update_time) has_change = write_file(hosts_content, update_time) if has_change: - try: - update_gitee_gist(session, hosts_content) - except Exception as e: - print("update gitee gist fail:{}".format(e)) + write_json_file(content_dict) print(hosts_content) diff --git a/hosts.json b/hosts.json new file mode 100644 index 000000000..8d55b7160 --- /dev/null +++ b/hosts.json @@ -0,0 +1 @@ +{"140.82.112.26": "alive.github.com", "140.82.114.25": "live.github.com", "185.199.108.154": "github.githubassets.com", "140.82.113.22": "central.github.com", "185.199.108.133": "media.githubusercontent.com", "185.199.108.153": "githubstatus.com", "199.232.69.194": "github.global.ssl.fastly.net", "140.82.112.4": "gist.github.com", "140.82.114.3": "github.com", "140.82.112.6": "api.github.com", "140.82.114.9": "codeload.github.com", "52.217.105.28": "github-cloud.s3.amazonaws.com", "52.216.178.147": "github-com.s3.amazonaws.com", "52.216.140.12": "github-production-release-asset-2e65be.s3.amazonaws.com", "52.217.196.241": "github-production-user-asset-6210df.s3.amazonaws.com", "52.217.128.49": "github-production-repository-file-5c1aeb.s3.amazonaws.com", "64.71.168.201": "github.community"} \ No newline at end of file