-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathupdate_ips.py
42 lines (34 loc) · 1004 Bytes
/
update_ips.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : XueWeiHan
# E-mail : [email protected]
# Date : 2025-01-16 15:27
# Desc : GitHub Action 运行的脚本
import json
from typing import Any, Optional
from retry import retry
from requests_html import HTMLSession
from common import write_hosts_content
@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
def main() -> None:
print('Start script.')
session = HTMLSession()
content = ""
content_list = get_json(session)
for item in content_list:
content += item[0].ljust(30) + item[1] + "\n"
hosts_content = write_hosts_content(content, content_list)
print(hosts_content)
print('End script.')
if __name__ == '__main__':
main()