From 0066162d4654e24957206c989fffc6a4394e4892 Mon Sep 17 00:00:00 2001 From: xueweihan <595666367@qq.com> Date: Tue, 22 Nov 2022 16:56:49 +0800 Subject: [PATCH] update --- fetch_ips.py | 40 ++++++++++++++++++++++++++-------------- hosts | 2 +- hosts.json | 1 - 3 files changed, 27 insertions(+), 16 deletions(-) delete mode 100644 hosts.json diff --git a/fetch_ips.py b/fetch_ips.py index 39f7144be..4e8e46fcb 100644 --- a/fetch_ips.py +++ b/fetch_ips.py @@ -16,10 +16,6 @@ from pythonping import ping from requests_html import HTMLSession from retry import retry -# GITHUB_URLS = [ -# 'alive.github.com' -# ] - GITHUB_URLS = [ 'alive.github.com', 'api.github.com', 'assets-cdn.github.com', 'avatars.githubusercontent.com', 'avatars0.githubusercontent.com', @@ -105,6 +101,18 @@ def get_best_ip(ip_list: list) -> str: return best_ip +@retry(tries=3) +def get_json(session: Any) -> Optional[list]: + url = 'https://raw.hellogithub.com/hosts.json' + try: + rs = session.get(url) + data = json.loads(rs.text) + return data + except Exception as ex: + print(f"get: {url}, error: {ex}") + raise Exception + + @retry(tries=3) def get_ip(session: Any, github_url: str) -> Optional[str]: url = f'https://www.ipaddress.com/site/{github_url}' @@ -133,16 +141,20 @@ def main(verbose=False) -> None: print('Start script.') session = HTMLSession() content = "" - content_list = [] - for index, github_url in enumerate(GITHUB_URLS): - try: - ip = get_ip(session, github_url) - content += ip.ljust(30) + github_url + "\n" - content_list.append((ip, github_url,)) - except Exception: - continue - if verbose: - print(f'process url: {index + 1}/{len(GITHUB_URLS)}') + content_list = get_json(session) + for item in content_list: + content += item[0].ljust(30) + item[1] + "\n" + # content_list = [] + # for index, github_url in enumerate(GITHUB_URLS): + # try: + # # ip = get_ip(session, github_url) + # + # content += ip.ljust(30) + github_url + "\n" + # content_list.append((ip, github_url,)) + # except Exception: + # continue + # if verbose: + # print(f'process url: {index + 1}/{len(GITHUB_URLS)}') if not content: return diff --git a/hosts b/hosts index 2a5c5ce39..a6ff8b688 100644 --- a/hosts +++ b/hosts @@ -39,7 +39,7 @@ 13.107.213.51 vscode.dev -# Update time: 2022-11-22T06:12:56+08:00 +# Update time: 2022-11-22T08:54:55+08:00 # Update url: https://raw.hellogithub.com/hosts # Star me: https://github.com/521xueweihan/GitHub520 # GitHub520 Host End diff --git a/hosts.json b/hosts.json deleted file mode 100644 index b63bc082a..000000000 --- a/hosts.json +++ /dev/null @@ -1 +0,0 @@ -[["140.82.114.25", "alive.github.com"], ["140.82.114.5", "api.github.com"], ["185.199.108.153", "assets-cdn.github.com"], ["185.199.109.133", "avatars.githubusercontent.com"], ["185.199.109.133", "avatars0.githubusercontent.com"], ["185.199.109.133", "avatars1.githubusercontent.com"], ["185.199.109.133", "avatars2.githubusercontent.com"], ["185.199.109.133", "avatars3.githubusercontent.com"], ["185.199.109.133", "avatars4.githubusercontent.com"], ["185.199.109.133", "avatars5.githubusercontent.com"], ["185.199.110.133", "camo.githubusercontent.com"], ["140.82.114.22", "central.github.com"], ["185.199.109.133", "cloud.githubusercontent.com"], ["140.82.113.10", "codeload.github.com"], ["140.82.113.22", "collector.github.com"], ["185.199.109.133", "desktop.githubusercontent.com"], ["185.199.109.133", "favicons.githubusercontent.com"], ["140.82.114.3", "gist.github.com"], ["54.231.236.105", "github-cloud.s3.amazonaws.com"], ["52.217.131.145", "github-com.s3.amazonaws.com"], ["52.217.166.25", "github-production-release-asset-2e65be.s3.amazonaws.com"], ["52.217.140.201", "github-production-repository-file-5c1aeb.s3.amazonaws.com"], ["52.217.72.20", "github-production-user-asset-6210df.s3.amazonaws.com"], ["192.0.66.2", "github.blog"], ["140.82.114.4", "github.com"], ["140.82.114.18", "github.community"], ["185.199.108.154", "github.githubassets.com"], ["151.101.65.194", "github.global.ssl.fastly.net"], ["185.199.111.153", "github.io"], ["185.199.109.133", "github.map.fastly.net"], ["185.199.108.153", "githubstatus.com"], ["140.82.114.26", "live.github.com"], ["185.199.109.133", "media.githubusercontent.com"], ["185.199.109.133", "objects.githubusercontent.com"], ["13.107.42.16", "pipelines.actions.githubusercontent.com"], ["185.199.109.133", "raw.githubusercontent.com"], ["185.199.109.133", "user-images.githubusercontent.com"], ["13.107.213.51", "vscode.dev"]] \ No newline at end of file