From d8a34926f99c8fe949630a2045c88ebb92cd8692 Mon Sep 17 00:00:00 2001 From: Scobiform Date: Wed, 17 Apr 2024 19:34:26 +0200 Subject: [PATCH] #1 node types --- start.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/start.py b/start.py index 88033fb..baa4ec6 100644 --- a/start.py +++ b/start.py @@ -25,8 +25,16 @@ async def get_graph(graph_data): async def generate_graph_data(user, followers, followings): # Add the authenticated user as the central node nodes = [{'id': user['id'], 'username': user['username']}] - nodes += [{'id': u['id'], 'username': u['username'], 'avatar': u['avatar']} for u in followers + followings] + + # Create nodes for followers with a type attribute + nodes_followers = [{'id': u['id'], 'username': u['username'], 'avatar': u['avatar'], 'type': 'follower'} for u in followers] + + # Create nodes for followings with a different type attribute + nodes_followings = [{'id': u['id'], 'username': u['username'], 'avatar': u['avatar'], 'type': 'following'} for u in followings] + # Combine all nodes + nodes += nodes_followers + nodes_followings + # Create links from the central user to each follower and following links = [{'source': user['id'], 'target': follower['id']} for follower in followers] links += [{'source': user['id'], 'target': following['id']} for following in followings]