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 class ysights.models.YDataHandler.YDataHandler.posts(): Retrieve all posts from database ysights.models.YDataHandler.YDataHandler.posts_by_agent(): Retrieve posts by specific agent

__init__()[source]

Initialize an empty Posts collection.

Methods

__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.

__init__()[source]

Initialize an empty Posts collection.

add_post(post)[source]

Add a post to the collection.

Parameters:

post (Post) – The Post object to add to the collection

Example:

posts = Posts()
post = Post(row_data)
posts.add_post(post)
get_posts()[source]

Retrieve the list of all posts in the collection.

Returns:

List of all Post objects in this collection

Return type:

list[Post]

Example:

posts = Posts()
# ... add posts ...
post_list = posts.get_posts()
for post in post_list:
    print(f"{post.id}: {post.text}")