Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyuyureka committed Feb 6, 2024
1 parent 0411263 commit e641ed1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions contrib/print_communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,16 @@ def read_communities() -> dict:
files = glob.glob(f"{sys.argv[1]}/*.txt")
for filename in files:
with open(filename, "r", encoding="utf8") as filehandle:
as_name = os.path.basename(filename).replace("as", "AS").removesuffix(".txt")
asn = os.path.basename(filename).removeprefix("as").removesuffix(".txt")
for entry in [line.strip() for line in filehandle.readlines()]:
if entry.startswith("#") or "," not in entry:
continue
(comm, desc) = entry.split(",", 1)
desc = f"{as_name}: {desc}"
if comm.startswith(f"{asn}:"):
desc = f"AS{asn}: {desc}"
elif os.path.basename(filename) == f"as{asn}.txt":
print(f"Ignoring community from {os.path.basename(filename)}, as it doesn't start with the asn", file=sys.stderr)
continue
ctype = get_community_type(comm)
if ctype == "unknown":
print(f"unknown communtity format: '{comm}'", file=sys.stderr)
Expand Down

0 comments on commit e641ed1

Please sign in to comment.