Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Read-only Twitter/X data: search tweets, user profiles, followers, replies, and retweets via twitterapi.io.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
exports.py
1"""2Twitter/X skill exports — script-mode wrapper around twitterapi.io.34Usage from a bash block:5python3 - <<'EOF'6import sys7sys.path.insert(0, "/data/workspace/skills/twitter")8from exports import twitter_user_info, twitter_search_tweets9print(twitter_user_info(username="elonmusk"))10EOF1112All 13 functions are flat, sync wrappers around TwitterApiClient methods.13HTTP traffic goes through sc-proxy via core.http_client — credentials14injected server-side, no TWITTER_API_KEY needed locally.15"""16from __future__ import annotations1718import os19import sys20from typing import List, Optional2122# Make local client.py importable regardless of caller cwd.23_THIS_DIR = os.path.dirname(os.path.abspath(__file__))24if _THIS_DIR not in sys.path:25sys.path.insert(0, _THIS_DIR)2627from client import TwitterApiClient # noqa: E4022829_client_singleton: Optional[TwitterApiClient] = None303132def _client() -> TwitterApiClient:33global _client_singleton34if _client_singleton is None:35_client_singleton = TwitterApiClient()36return _client_singleton373839# ── Tweet endpoints ──────────────────────────────────────────────────────────404142def twitter_search_tweets(query: str, cursor: Optional[str] = None) -> dict:43"""Search Twitter/X tweets using advanced query syntax.4445Operators: from:user, to:user, #hashtag, $cashtag, lang:en, has:media,46has:links, is:reply, min_faves:100, since:YYYY-MM-DD, until:YYYY-MM-DD.4748Returns dict with `tweets` array and `next_cursor` for pagination.49"""50return _client().search_tweets(query, cursor=cursor)515253def twitter_get_tweets(tweet_ids: List[str]) -> dict:54"""Get one or more tweets by their tweet IDs.5556`tweet_ids` is a list of stringified tweet IDs.57Returns dict with `tweets` array containing full tweet data.58"""59if isinstance(tweet_ids, str):60# Be forgiving — accept comma string too.61tweet_ids = [t.strip() for t in tweet_ids.split(",") if t.strip()]62return _client().get_tweets(tweet_ids)636465def twitter_tweet_replies(tweet_id: str, cursor: Optional[str] = None) -> dict:66"""Get replies to a specific tweet (by tweet ID)."""67return _client().get_tweet_replies(tweet_id, cursor=cursor)686970def twitter_tweet_retweeters(tweet_id: str, cursor: Optional[str] = None) -> dict:71"""Get users who retweeted a specific tweet."""72return _client().get_tweet_retweeters(tweet_id, cursor=cursor)737475def twitter_tweet_thread_context(tweet_id: str) -> dict:76"""Get full thread context for a tweet (parent chain + direct replies)."""77return _client().get_tweet_thread_context(tweet_id)787980def twitter_tweet_quote(tweet_id: str, cursor: Optional[str] = None) -> dict:81"""Get quote tweets that quote a specific tweet."""82return _client().get_tweet_quote(tweet_id, cursor=cursor)838485def twitter_get_article(tweet_id: str) -> dict:86"""Get long-form X article content by the article's tweet ID."""87return _client().get_article(tweet_id)888990def twitter_get_trends(91woeid: Optional[str] = None,92country: Optional[str] = None,93category: Optional[str] = None,94limit: Optional[int] = None,95) -> dict:96"""Get Twitter/X trending topics.9798All filters optional. `woeid` = Where On Earth ID (numeric region code).99"""100return _client().get_trends(woeid=woeid, country=country, category=category, limit=limit)101102103# ── User endpoints ───────────────────────────────────────────────────────────104105106def twitter_user_info(username: str) -> dict:107"""Get a user's profile: bio, follower/following count, tweet count, verified."""108return _client().get_user_info(username)109110111def twitter_user_tweets(username: str, cursor: Optional[str] = None) -> dict:112"""Get a user's recent tweets (paginated)."""113return _client().get_user_tweets(username, cursor=cursor)114115116def twitter_user_followers(username: str, cursor: Optional[str] = None) -> dict:117"""Get a user's followers (paginated)."""118return _client().get_user_followers(username, cursor=cursor)119120121def twitter_user_followings(username: str, cursor: Optional[str] = None) -> dict:122"""Get accounts a user follows (paginated)."""123return _client().get_user_followings(username, cursor=cursor)124125126def twitter_search_users(query: str, cursor: Optional[str] = None) -> dict:127"""Search for users by name or keyword."""128return _client().search_users(query, cursor=cursor)129130131__all__ = [132"twitter_search_tweets",133"twitter_get_tweets",134"twitter_tweet_replies",135"twitter_tweet_retweeters",136"twitter_tweet_thread_context",137"twitter_tweet_quote",138"twitter_get_article",139"twitter_get_trends",140"twitter_user_info",141"twitter_user_tweets",142"twitter_user_followers",143"twitter_user_followings",144"twitter_search_users",145]146