mirror of
https://github.com/Toperlock/sing-box-geosite.git
synced 2025-06-08 09:42:14 +08:00
optimized code
This commit is contained in:
parent
3a932ab5c9
commit
d684dae2b0
19
main.py
19
main.py
@ -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'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user