ysights.models.Posts
- class ysights.models.Posts[source]
A container class for managing a collection of Post objects.
This class provides methods to add posts to the collection and retrieve the list of posts. It serves as a convenient way to group and manipulate multiple posts from a YSocial simulation.
- Variables:
posts (list) – Internal list storing all Post objects
Example
Managing a collection of posts:
from ysights import YDataHandler from ysights.models.Posts import Posts, Post # Create a posts collection posts = Posts() # Add posts manually row = (1, 'Hello world!', None, 5, None, 1, 10, None, None, None) post = Post(row) posts.add_post(post) # Or retrieve posts from database ydh = YDataHandler('path/to/database.db') agent_posts = ydh.posts_by_agent(agent_id=5, enrich_dimensions=['sentiment']) # Get list of all posts post_list = agent_posts.get_posts() print(f"Total posts: {len(post_list)}") # Iterate through posts for post in post_list: print(f"Post {post.id}: {post.text[:50]}...") if post.sentiment: print(f" Sentiment: {post.sentiment}")
See also
Post: Individual post classysights.models.YDataHandler.YDataHandler.posts(): Retrieve all posts from databaseysights.models.YDataHandler.YDataHandler.posts_by_agent(): Retrieve posts by specific agentMethods
__init__()Initialize an empty Posts collection.
add_post(post)Add a post to the collection.
get_posts()Retrieve the list of all posts in the collection.