twitter

package
v0.0.11-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLoggedIn

func IsLoggedIn(scraper *twitterscraper.Scraper) bool

func LoadCookies

func LoadCookies(scraper *twitterscraper.Scraper, filePath string) error

func Login

func Login(scraper *twitterscraper.Scraper, credentials ...string) error

Login attempts to log in to the Twitter scraper service. It supports three modes of operation: 1. Basic login using just a username and password. 2. Login requiring an email confirmation, using a username, password, and email address. 3. Login with two-factor authentication, using a username, password, and 2FA code. Parameters:

  • scraper: A pointer to an instance of the twitterscraper.Scraper.
  • credentials: A variadic list of strings representing login credentials. The function expects either two strings (username, password) for basic login, or three strings (username, password, email/2FA code) for email confirmation or 2FA.

Returns an error if login fails or if an invalid number of credentials is provided.

func Logout

func Logout(scraper *twitterscraper.Scraper) error

func NewManager

func NewManager() actor.Producer

NewManager creates and returns a new actor.Producer function. This function, when invoked, will produce an instance of a Manager actor receiver. The Manager is responsible for managing a pool of worker actors that process tweet requests.

func NewTweetWorker

func NewTweetWorker(t *TweetRequest, pid *actor.PID) actor.Producer

NewTweetWorker creates and returns a new actor.Producer function specific for tweet workers. This function, when invoked, will produce an instance of a TweetWorker actor receiver, initialized with the provided TweetRequest and PID. Parameters: - t: A pointer to a TweetRequest struct containing the details of the tweet queries to process. - pid: A pointer to an actor.PID representing the process identifier for the actor system. Returns: - An actor.Producer function that produces TweetWorker actor receivers.

func SaveCookies

func SaveCookies(scraper *twitterscraper.Scraper, filePath string) error

func ScrapeTweetsByQuery

func ScrapeTweetsByQuery(query string, count int) ([]*twitterscraper.Tweet, error)

ScrapeTweetsByQuery performs a search on Twitter for tweets matching the specified query. It fetches up to the specified count of tweets and returns a slice of Tweet pointers. Parameters:

  • query: The search query string to find matching tweets.
  • count: The maximum number of tweets to retrieve.

Returns:

  • A slice of pointers to twitterscraper.Tweet objects that match the search query.
  • An error if the scraping process encounters any issues.

func ScrapeTweetsByTrends

func ScrapeTweetsByTrends() ([]string, error)

ScrapeTweetsByTrends scrapes the current trending topics on Twitter. It returns a slice of strings representing the trending topics. If an error occurs during the scraping process, it returns an error.

func ScrapeTweetsProfile

func ScrapeTweetsProfile(username string) (twitterscraper.Profile, error)

ScrapeTweetsProfile scrapes the profile and tweets of a specific Twitter user. It takes the username as a parameter and returns the scraped profile information and an error if any.

func ScrapeTweetsUsingActors

func ScrapeTweetsUsingActors(node *masa.OracleNode, query string, count int, model string) (string, error)

ScrapeTweetsUsingActors initiates the process of scraping tweets based on a given query, count, and model. It leverages actor-based concurrency to manage the scraping and analysis tasks. The function spawns a new actor worker and sends a TweetRequest message to the Manager actor. It then waits for a sentiment analysis result to be sent back through a channel. Parameters:

  • query: The search query for fetching tweets.
  • count: The number of tweets to fetch and analyze.
  • model: The sentiment analysis model to use. -- claude-3-opus-20240229 -- claude-3-sonnet-20240229 -- claude-3-haiku-20240307 -- gpt-4 -- gpt-4-turbo-preview -- gpt-3.5-turbo

Returns: - A string containing the sentiment analysis summary. - An error if the process fails at any point.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is a struct that maintains a map of worker actors. The map keys are pointers to actor.PID (Process Identifiers) and the values are booleans indicating the worker's availability.

func (*Manager) Receive

func (m *Manager) Receive(c *actor.Context)

Receive processes messages sent to the Manager actor. It handles different types of messages such as TweetRequest, actor.Started, and actor.Stopped by switching over the type of the message. For TweetRequest messages, it delegates the handling to the handleTweetRequest method. For actor.Started and actor.Stopped messages, it logs the state of the actor worker.

type TweetRequest

type TweetRequest struct {
	Count int      // Number of tweets to fetch
	Query []string // Keywords or phrases to search for
	Model string   // Language model for sentiment analysis
}

TweetRequest represents the parameters for a request to fetch and analyze tweets. Count specifies the number of tweets to fetch. Query is a list of keywords or phrases to search for within tweets. Model indicates the language model to use for analyzing the sentiment of the tweets.

type TweetWorker

type TweetWorker struct {
	TweetRequest // Embedding TweetRequest to inherit its fields
	// contains filtered or unexported fields
}

TweetWorker represents a worker entity capable of processing TweetRequests. It embeds TweetRequest to inherit its fields and adds a pid field to hold the worker's process identifier.

func (*TweetWorker) Receive

func (w *TweetWorker) Receive(c *actor.Context)

Receive processes messages sent to the TweetWorker actor. It handles different types of messages such as actor.Started and actor.Stopped by switching over the type of the message. For actor.Started messages, it initiates the process of scraping tweets based on the query and count specified in the TweetWorker, analyzes the sentiment of the scraped tweets, and then stops the worker actor. For actor.Stopped messages, it simply logs that the worker has stopped.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL