️ 新增 CSV

This commit is contained in:
踢低吸 2023-07-10 07:38:34 +00:00
parent f3fb7210da
commit e4d95e0442

View File

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