1
0
mirror of synced 2024-07-07 20:45:13 +08:00
This commit is contained in:
xueweihan 2021-05-31 13:59:34 +08:00
parent f1e97429a9
commit fadb287ae7
4 changed files with 21 additions and 12 deletions

View File

@ -66,6 +66,7 @@
上面内容会自动定时更新保证最新有效。数据更新时间2021-05-31T12:58:34+08:00内容无变动不会更新
### 2.1 手动方式
#### 2.1.1 修改 hosts 文件
hosts 文件在每个系统的位置不一,详情如下:

View File

@ -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`

View File

@ -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)

1
hosts.json Normal file
View File

@ -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"}