Overview
The Twitter class provides automated posting functionality for Twitter/X accounts. It handles post generation and publishing using Selenium WebDriver.
Constructor
Twitter(
account_uuid: str,
account_nickname: str,
fp_profile_path: str,
topic: str
)
The path to the Firefox profile logged into the Twitter account
The topic for post generation
Example:
twitter = Twitter(
account_uuid="uuid-456",
account_nickname="Tech News Bot",
fp_profile_path="/path/to/firefox/profile",
topic="Technology and AI"
)
Methods
post
def post(text: Optional[str] = None) -> None
Posts content to Twitter. If no text is provided, generates a post automatically.
Optional text to post. If None, generates a post using generate_post()
Returns: None
Example:
# Post custom text
twitter.post("Check out this amazing new AI tool!")
# Auto-generate and post
twitter.post() # Will generate based on topic
generate_post
def generate_post() -> str
Generates a post for the Twitter account based on the topic.
Returns: str - The generated post (limited to 260 characters)
Example:
post_content = twitter.generate_post()
print(f"Generated post: {post_content}")
get_posts
def get_posts() -> List[dict]
Gets the posts from the cache.
Returns: List[dict] - List of posts, each containing:
content (str): Post content
date (str): Post date in format “mm/dd/yyyy, HH:MM:SS”
Example:
posts = twitter.get_posts()
for post in posts:
print(f"{post['date']}: {post['content']}")
add_post
def add_post(post: dict) -> None
Adds a post to the cache.
The post to add, containing:
content (str): Post content
date (str): Post date
Returns: None