Merge pull request #100 from FutaGuard/refactor/workflow-tw165

Refactor workflow
This commit is contained in:
踢低吸 2023-07-08 19:08:51 +08:00 committed by GitHub
commit bfed1163ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,7 @@ def main():
r_json = r.json()['result']['records']
except (JSONDecodeError, KeyError):
logger.critical('Parse JSON Err')
raise
# check if file exists
filename = 'TW165.txt'
@ -34,16 +35,18 @@ def main():
with open(filename, 'r') as f:
read_ = f.read().splitlines()
for row in r_json[1:]:
domain = urlparse('http://'+row['WEBURL']).hostname
if domain not in read_:
added_list.append(domain)
with open(filename, 'a+') as f:
f.write('\n')
f.write(
'\n'.join(e for e in added_list)
)
current_domains = frozenset(read_)
for row in r_json[1:]:
domain = urlparse('http://'+row['WEBURL']).hostname
if domain not in current_domains:
added_list.append(domain)
if added_list:
with open(filename, 'a+') as f:
f.write('\n')
f.write(
'\n'.join(e for e in added_list)
)
if __name__ == '__main__':
main()