From e4d95e0442663c31fcd6cbe59626c019d6316b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B8=A2=E4=BD=8E=E5=90=B8?= Date: Mon, 10 Jul 2023 07:38:34 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20=E6=96=B0=E5=A2=9E=20CSV?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutoBuild/tw_165.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/AutoBuild/tw_165.py b/AutoBuild/tw_165.py index 69f2307..ba5bb73 100644 --- a/AutoBuild/tw_165.py +++ b/AutoBuild/tw_165.py @@ -12,8 +12,9 @@ logger = logging.getLogger(__name__) def main(): auth = os.getenv('auth', None) - url = os.getenv('tw165json', None) - if not url: + jsonurl = os.getenv('tw165json', None) + csvurl = os.getenv('tw165csv', None) + if not jsonurl or not csvurl: logger.critical('URL NOT SET') return if not auth: @@ -22,11 +23,15 @@ def main(): user, passwd = auth.split(':') basic = HTTPBasicAuth(user, passwd) - r = requests.get(url, auth=basic) - if r.status_code != 200: - logger.critical('Fetch Data Err') - return + def fetchdata(url): + r = requests.get(url, auth=basic) + if r.status_code != 200: + logger.critical('Fetch Data Err') + return + return r + + r = fetchdata(jsonurl) try: r_json = r.json()['result']['records'] except (JSONDecodeError, KeyError): @@ -38,6 +43,14 @@ def main(): for row in r_json[1:] ]) + r = fetchdata(csvurl) + domains.update(dict.fromkeys( + [ + x.split(',')[1] + for x in r.text.splitlines()[2:] + ] + )) + filename = 'TW165.txt' with open(filename, 'w') as f: f.write('\n'.join(domains.keys()))