-
Notifications
You must be signed in to change notification settings - Fork 1
/
neighbors.py
executable file
·34 lines (27 loc) · 978 Bytes
/
neighbors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
import argparse
import data_reader
def main():
parser = argparse.ArgumentParser()
parser.add_argument("people", nargs="+")
parser.add_argument("--only-ids", action="store_true")
parser.add_argument("--version", help="Data version (defaults to most recent).")
args = parser.parse_args()
db = data_reader.Database(args.version)
for id_or_num in args.people:
user_num = db.get_person_num(id_or_num)
if args.only_ids:
print(db.num2id(user_num))
else:
print("Neighbors of:", db.name_of(user_num), db.num2id(user_num), user_num)
neighbors = [(db.relationship_type(user_num, neigh), neigh)
for neigh in db.neighbors_of(user_num)]
neighbors.sort()
for rel_type, neigh in neighbors:
if args.only_ids:
print(db.num2id(neigh))
else:
print(f" - {rel_type:10} {db.name_of(neigh):30} {db.num2id(neigh):20} {neigh:10}")
print()
if __name__ == "__main__":
main()