Added more get methods to client
Browse files
postly/clients/postly_client.py
CHANGED
@@ -78,25 +78,48 @@ class PostlyClient:
|
|
78 |
raise KeyError(f"User '{user_name}' not found.")
|
79 |
|
80 |
self.userPosts.pop(user_name, None)
|
81 |
-
|
82 |
def get_users(self):
|
83 |
"""
|
84 |
Get all users.
|
85 |
-
|
86 |
Returns:
|
87 |
A list of users.
|
88 |
"""
|
89 |
return list(self.userPosts.keys())
|
90 |
-
|
91 |
def get_posts(self):
|
92 |
"""
|
93 |
Get all posts for all users.
|
94 |
-
|
95 |
Returns:
|
96 |
A dictionary of posts.
|
97 |
"""
|
98 |
return self.userPosts
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
def get_posts_for_user(self, user_name: str) -> List[str]:
|
101 |
"""
|
102 |
Get all posts for user, sorted by timestamp in descending order.
|
|
|
78 |
raise KeyError(f"User '{user_name}' not found.")
|
79 |
|
80 |
self.userPosts.pop(user_name, None)
|
81 |
+
|
82 |
def get_users(self):
|
83 |
"""
|
84 |
Get all users.
|
85 |
+
|
86 |
Returns:
|
87 |
A list of users.
|
88 |
"""
|
89 |
return list(self.userPosts.keys())
|
90 |
+
|
91 |
def get_posts(self):
|
92 |
"""
|
93 |
Get all posts for all users.
|
94 |
+
|
95 |
Returns:
|
96 |
A dictionary of posts.
|
97 |
"""
|
98 |
return self.userPosts
|
99 |
|
100 |
+
def get_topics(self) -> List[str]:
|
101 |
+
"""
|
102 |
+
Get all topics.
|
103 |
+
|
104 |
+
Returns:
|
105 |
+
A list of topics.
|
106 |
+
"""
|
107 |
+
topics = set()
|
108 |
+
for user in self.userPosts:
|
109 |
+
for post_data in self.userPosts[user]:
|
110 |
+
topics.update(post_data.topics)
|
111 |
+
|
112 |
+
return list(topics)
|
113 |
+
|
114 |
+
def get_current_timestamp(self) -> int:
|
115 |
+
"""
|
116 |
+
Get the current timestamp.
|
117 |
+
|
118 |
+
Returns:
|
119 |
+
The current timestamp.
|
120 |
+
"""
|
121 |
+
return self.timestamp_iter
|
122 |
+
|
123 |
def get_posts_for_user(self, user_name: str) -> List[str]:
|
124 |
"""
|
125 |
Get all posts for user, sorted by timestamp in descending order.
|