optimized code

This commit is contained in:
Dorae 2024-01-26 20:10:02 +08:00 committed by GitHub
parent 3a932ab5c9
commit d684dae2b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

19
main.py
View File

@ -34,28 +34,13 @@ def parse_and_convert_to_dataframe(link):
yaml_data = read_yaml_from_url(link) yaml_data = read_yaml_from_url(link)
rows = [] rows = []
if not isinstance(yaml_data, str): if not isinstance(yaml_data, str):
for item in yaml_data.get('payload', []): items = yaml_data.get('payload', [])
address = item.strip("'")
if ',' not in item:
if is_ipv4_or_ipv6(item):
pattern = 'IP-CIDR'
else:
if address.startswith('+'):
pattern = 'DOMAIN-SUFFIX'
address = address[1:]
if address.startswith('.'):
address = address[1:]
else:
pattern = 'DOMAIN'
else:
pattern, address = item.split(',', 1)
rows.append({'pattern': pattern.strip(), 'address': address.strip(), 'other': None})
else: else:
lines = yaml_data.splitlines() lines = yaml_data.splitlines()
line_content = lines[0] line_content = lines[0]
items = line_content.split() items = line_content.split()
for item in items: for item in items:
address = item address = item.strip("'")
if ',' not in item: if ',' not in item:
if is_ipv4_or_ipv6(item): if is_ipv4_or_ipv6(item):
pattern = 'IP-CIDR' pattern = 'IP-CIDR'