From ec70ccdc5430e971bc635e895eb982c6fab65028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B8=A2=E4=BD=8E=E5=90=B8?= Date: Sat, 29 Jul 2023 19:49:10 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=91=EF=B8=8F=20=E6=95=B4=E7=90=86?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=B8=8D=E5=BF=85=E8=A6=81=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutoBuild/tw_165.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/AutoBuild/tw_165.py b/AutoBuild/tw_165.py index 259dfe1..c77eed0 100644 --- a/AutoBuild/tw_165.py +++ b/AutoBuild/tw_165.py @@ -1,11 +1,11 @@ -import requests -from requests.auth import HTTPBasicAuth -from json.decoder import JSONDecodeError import logging import os import re +from json.decoder import JSONDecodeError from urllib.parse import urlparse +import requests +from requests.auth import HTTPBasicAuth logger = logging.getLogger(__name__) @@ -25,7 +25,7 @@ def main(): if not auth: logger.critical('AUTH NOT SET') return - + user, passwd = auth.split(':') basic = HTTPBasicAuth(user, passwd) @@ -35,7 +35,7 @@ def main(): logger.critical('Fetch Data Err') return return r - + r = fetchdata(jsonurl) try: r_json = r.json()['result']['records'] @@ -44,23 +44,29 @@ def main(): raise domains = dict.fromkeys([ - urlparse(row['WEBURL']).hostname if row['WEBURL'].startswith('http') else urlparse('http://'+row['WEBURL']).hostname + urlparse(row['WEBURL']).hostname if row['WEBURL'].startswith('http') else urlparse( + 'http://' + row['WEBURL']).hostname for row in r_json[1:] ]) r = fetchdata(csvurl) domains.update(dict.fromkeys( [ - urlparse(x.split(',')[1]).hostname if x.split(',')[1].startswith('http') else urlparse('http://'+x.split(',')[1]).hostname + urlparse(x.split(',')[1]).hostname if x.split(',')[1].startswith('http') else urlparse( + 'http://' + x.split(',')[1]).hostname for x in r.text.splitlines()[2:] ] )) # 移除純 IP domains = {k: v for k, v in domains.items() if not is_pure_ip(k)} + filename = 'TW165.txt' with open(filename, 'w') as f: f.write('^\n'.join('||' + e for e in domains.keys())) + + + if __name__ == '__main__': main()