Added get methods to postly client; removed redundant arg to add_post
Browse files
postly/clients/postly_client.py
CHANGED
@@ -41,14 +41,13 @@ class PostlyClient:
|
|
41 |
"""
|
42 |
self.userPosts[user_name] = []
|
43 |
|
44 |
-
def add_post(self, user_name: str, post_text: str
|
45 |
"""
|
46 |
Add new post to the user's post history.
|
47 |
|
48 |
Args:
|
49 |
user_name: The name of the user to add the post to.
|
50 |
post_text: The text of the post.
|
51 |
-
timestamp: The timestamp of the post.
|
52 |
Returns:
|
53 |
None
|
54 |
"""
|
@@ -61,9 +60,6 @@ class PostlyClient:
|
|
61 |
if not post_text.strip():
|
62 |
raise ValueError("Post cannot be empty.")
|
63 |
|
64 |
-
if not isinstance(timestamp, int) or timestamp < 0:
|
65 |
-
raise ValueError("Timestamp must be a non-negative integer.")
|
66 |
-
|
67 |
self.timestamp_iter += 1
|
68 |
curr_topics = self.get_topics_from_post(post_text)
|
69 |
|
@@ -82,6 +78,24 @@ class PostlyClient:
|
|
82 |
raise KeyError(f"User '{user_name}' not found.")
|
83 |
|
84 |
self.userPosts.pop(user_name, None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
def get_posts_for_user(self, user_name: str) -> List[str]:
|
87 |
"""
|
|
|
41 |
"""
|
42 |
self.userPosts[user_name] = []
|
43 |
|
44 |
+
def add_post(self, user_name: str, post_text: str) -> None:
|
45 |
"""
|
46 |
Add new post to the user's post history.
|
47 |
|
48 |
Args:
|
49 |
user_name: The name of the user to add the post to.
|
50 |
post_text: The text of the post.
|
|
|
51 |
Returns:
|
52 |
None
|
53 |
"""
|
|
|
60 |
if not post_text.strip():
|
61 |
raise ValueError("Post cannot be empty.")
|
62 |
|
|
|
|
|
|
|
63 |
self.timestamp_iter += 1
|
64 |
curr_topics = self.get_topics_from_post(post_text)
|
65 |
|
|
|
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 |
"""
|