Documentation
¶
Overview ¶
Package yrs provides a Go client library for searching tweets (X/Twitter posts) via Yahoo! Japan Realtime Search. It scrapes the __NEXT_DATA__ JSON from Yahoo! Realtime Search pages, providing a clean, typed API without requiring any API keys or authentication.
Basic Usage:
client := yrs.NewClient()
result, err := client.Search(context.Background(), "golang")
if err != nil {
log.Fatal(err)
}
for _, tw := range result.Tweets {
fmt.Printf("@%s: %s\n", tw.ScreenName, tw.Text)
}
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Search(ctx context.Context, query string) (*SearchResult, error)
- func (c *Client) SearchWithLimit(ctx context.Context, query string, limit int) (*SearchResult, error)
- func (c *Client) SearchWithQuery(ctx context.Context, q *Query) (*SearchResult, error)
- func (c *Client) SearchWithQueryAndLimit(ctx context.Context, q *Query, limit int) (*SearchResult, error)
- type ClientConfig
- type ClientOption
- type Image
- type Query
- func (q *Query) And(keywords ...string) *Query
- func (q *Query) Build() (string, error)
- func (q *Query) FromUser(username string) *Query
- func (q *Query) Hashtag(tags ...string) *Query
- func (q *Query) Not(keywords ...string) *Query
- func (q *Query) Or(keywords ...string) *Query
- func (q *Query) ToUser(username string) *Query
- func (q *Query) URL(urlOrDomain string) *Query
- type SearchResult
- type Tweet
Constants ¶
const ( // LibraryName is the name of this library. LibraryName = "go-yahoo-realtime-search" // LibraryVersion is the current version of this library. LibraryVersion = "0.1.0" // DefaultUserAgent is the default User-Agent header sent with HTTP requests. DefaultUserAgent = LibraryName + "/" + LibraryVersion // DefaultRequestTimeout is the default timeout for HTTP requests. DefaultRequestTimeout = 30 * time.Second )
Variables ¶
var ( // ErrScrapeFailed is returned when the HTML scraping fails // (e.g., __NEXT_DATA__ not found, unexpected structure, non-200 HTTP status). ErrScrapeFailed = errors.New("yrs: scraping failed") // ErrInvalidParameter is returned for invalid input parameters. ErrInvalidParameter = errors.New("yrs: invalid parameter") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Yahoo Realtime Search client.
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
NewClient creates a new Yahoo Realtime Search client.
func (*Client) SearchWithLimit ¶
func (c *Client) SearchWithLimit(ctx context.Context, query string, limit int) (*SearchResult, error)
SearchWithLimit performs a search with a maximum number of results. A limit of 0 means no limit (return all results from the page).
func (*Client) SearchWithQuery ¶
SearchWithQuery performs a search using a Query builder.
func (*Client) SearchWithQueryAndLimit ¶
func (c *Client) SearchWithQueryAndLimit(ctx context.Context, q *Query, limit int) (*SearchResult, error)
SearchWithQueryAndLimit performs a search using a Query builder with a result limit.
type ClientConfig ¶
ClientConfig holds the resolved configuration for the client.
type ClientOption ¶
type ClientOption func(*ClientConfig)
ClientOption configures the Client.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient sets a custom HTTP client.
func WithRequestTimeout ¶
func WithRequestTimeout(timeout time.Duration) ClientOption
WithRequestTimeout sets the timeout for HTTP requests.
func WithUserAgent ¶
func WithUserAgent(ua string) ClientOption
WithUserAgent sets a custom User-Agent header.
type Image ¶
type Image struct {
URL string `json:"url"`
}
Image represents an image attached to a tweet.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query builds a Yahoo Realtime Search query string.
type SearchResult ¶
SearchResult holds the result of a Yahoo Realtime Search query.
type Tweet ¶
type Tweet struct {
ID string `json:"id"`
URL string `json:"url"`
Text string `json:"text"`
AuthorName string `json:"author_name"`
ScreenName string `json:"screen_name"`
CreatedAt time.Time `json:"created_at"`
ReplyCount int `json:"reply_count"`
RTCount int `json:"rt_count"`
LikeCount int `json:"like_count"`
Images []Image `json:"images,omitempty"`
}
Tweet represents a single tweet extracted from Yahoo Realtime Search.