tweets

package
v0.0.0-...-4579cc6 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FailedToRetrieveArticles       = errors.New("failed to retrieve articles")
	EmptyStateNoArticlesToRetrieve = errors.New("empty state, no articles to retrieve")
	FailedToRetrieveArticle        = errors.New("failed to retrieve article")

	FailedToObtainTweetAuthorElement       = errors.New("failed to obtain tweet author element")
	FailedToObtainTweetAuthor              = errors.New("failed to obtain tweet author")
	FailedToObtainQuotedTweetAuthorElement = errors.New("failed to obtain quoted tweet author element")
	FailedToObtainQuotedTweetAuthor        = errors.New("failed to obtain quoted tweet author")
	FailedToObtainTweetAuthorInformation   = errors.New("failed to obtain tweet author information")

	FailedToObtainTweetAvatarElement            = errors.New("failed to obtain tweet avatar element")
	FailedToObtainTweetAvatarImage              = errors.New("failed to obtain tweet avatar image")
	FailedToObtainTweetAvatarSrcFromImage       = errors.New("failed to obtain tweet avatar src from image")
	FailedToObtainQuotedTweetAvatarElement      = errors.New("failed to obtain quoted tweet avatar element")
	FailedToObtainQuotedTweetAvatarImage        = errors.New("failed to obtain quoted tweet avatar image")
	FailedToObtainQuotedTweetAvatarSrcFromImage = errors.New("failed to obtain quoted tweet avatar src from image")

	FailedToObtainTweetIDElement                    = errors.New("failed to obtain tweet ID element")
	FailedToObtainTweetIDATag                       = errors.New("failed to obtain tweet ID a tag")
	FailedToObtainTweetIDATagHref                   = errors.New("failed to obtain tweet ID a tag href")
	FailedToObtainTweetIDElementFromTweetPageHeader = errors.New("failed to obtain tweet ID from tweet page header")
	FailedToObtainTweetIDElementFromTweetPageFooter = errors.New("failed to obtain tweet ID from tweet page footer")
	FailedToObtainTweetIDElementFromTweetPage       = errors.New("failed to obtain tweet ID from tweet page footer")

	FailedToObtainTweetTimestampElement       = errors.New("failed to obtain tweet timestamp element")
	FailedToObtainTweetTimestampTimeTag       = errors.New("failed to obtain tweet timestamp time tag")
	FailedToObtainTweetTimestamp              = errors.New("failed to obtain tweet timestamp")
	FailedToObtainQuotedTweetTimestampElement = errors.New("failed to obtain quoted tweet timestamp element")
	FailedToObtainQuotedTweetTimestampTimeTag = errors.New("failed to obtain quoted tweet timestamp time tag")
	FailedToObtainQuotedTweetTimestamp        = errors.New("failed to obtain quoted tweet timestamp")
	FailedToObtainTweetTimestampInformation   = errors.New("failed to obtain tweet timestamp information")

	FailedToObtainTweetTextElement     = errors.New("failed to obtain tweet text element")
	FailedToObtainTweetTextParts       = errors.New("failed to obtain tweet text parts")
	FailedToObtainTweetTextPartTagName = errors.New("failed to obtain tweet text part tag name")
	FailedToObtainTweetTextFromSpan    = errors.New("failed to obtain tweet text from span")

	FailedToLoadTweetPage                  = errors.New("failed to load tweet page")
	FailedToObtainTweetLongTextElement     = errors.New("failed to obtain tweet long text element")
	FailedToObtainTweetLongTextParts       = errors.New("failed to obtain tweet long text parts")
	FailedToObtainTweetLongTextPartTagName = errors.New("failed to obtain tweet long text part tag name")
	FailedToObtainTweetLongTextFromSpan    = errors.New("failed to obtain tweet long text from span")
	FailedToCloseOpenedTabs                = errors.New("failed close opened tabs")

	FailedToObtainQuotedTweetTextElement     = errors.New("failed to obtain quoted tweet text element")
	FailedToObtainQuotedTweetTextParts       = errors.New("failed to obtain quoted tweet text parts")
	FailedToObtainQuotedTweetTextPartTagName = errors.New("failed to obtain quoted tweet text part tag name")
	FailedToObtainQuotedTweetTextFromSpan    = errors.New("failed to obtain quoted tweet text from span")

	FailedToObtainTweetImagesElement       = errors.New("failed to obtain tweet images element")
	FailedToObtainTweetImages              = errors.New("failed to obtain tweet images")
	FailedToObtainTweetSrcFromImage        = errors.New("failed to obtain tweet src from image")
	FailedToObtainQuotedTweetImagesElement = errors.New("failed to obtain quoted tweet images element")
	FailedToObtainQuotedTweetImages        = errors.New("failed to obtain quoted tweet images")
	FailedToObtainQuotedTweetSrcFromImage  = errors.New("failed to obtain quoted tweet src from image")
)

Functions

func MockLongTextElement

MockLongTextElement mocks the tweet Long Text Elements, its dependencies and all the functions that will be executed on them

Types

type Data

type Data struct {
	Author    string
	Avatar    string
	Timestamp string
	IsAReply  bool
	HasText   bool
	HasImages bool
	Text      string
	Images    []string
}

Data defines the selected parts of a tweets that will be saved

func (Data) String

func (data Data) String() string

String converts Data properties to a string

type GetAuthor

type GetAuthor func(ctx context.Context, tweetArticleElement selenium.WebElement) (string, error)

GetAuthor retrieves the tweet author

func MakeGetAuthor

func MakeGetAuthor() GetAuthor

MakeGetAuthor creates a new GetAuthor

func MockGetAuthor

func MockGetAuthor(author string, err error) GetAuthor

MockGetAuthor mocks GetAuthor function

type GetAvatar

type GetAvatar func(ctx context.Context, tweetArticleElement selenium.WebElement) (string, error)

GetAvatar retrieves the tweet author's avatar

func MakeGetAvatar

func MakeGetAvatar() GetAvatar

MakeGetAvatar creates a new GetAvatar

func MockGetAvatar

func MockGetAvatar(avatar string, err error) GetAvatar

MockGetAvatar mocks GetAvatar function

type GetID

type GetID func(ctx context.Context, tweetArticleElement selenium.WebElement) (string, error)

GetID retrieves the ID of the tweet

func MakeGetID

func MakeGetID() GetID

MakeGetID creates a new GetID

func MockGetID

func MockGetID(id string, err error) GetID

MockGetID mocks GetID function

type GetIDFromTweetPage

type GetIDFromTweetPage func(ctx context.Context, tweetArticleElement selenium.WebElement) (string, error)

GetIDFromTweetPage retrieves the ID of a tweet from the opened tweet page

func MakeGetIDFromTweetPage

func MakeGetIDFromTweetPage() GetIDFromTweetPage

MakeGetIDFromTweetPage creates a new GetIDFromTweetPage

func MockGetIDFromTweetPage

func MockGetIDFromTweetPage(id string, err error) GetIDFromTweetPage

MockGetIDFromTweetPage mocks GetIDFromTweetPage function

type GetImages

type GetImages func(ctx context.Context, tweetArticleElement selenium.WebElement, isAReply bool) ([]string, error)

GetImages retrieves the tweet images

func MakeGetImages

func MakeGetImages() GetImages

MakeGetImages creates a new GetImages

func MockGetImages

func MockGetImages(urls []string, err error) GetImages

MockGetImages mocks GetImages function

type GetLongText

type GetLongText func(ctx context.Context, tweetElement selenium.WebElement, isAReply bool) (string, error)

GetLongText retrieves the tweet text when it is so long that the Show More link is displayed

func MakeGetLongText

func MakeGetLongText() GetLongText

MakeGetLongText creates a new GetLongText

func MockGetLongText

func MockGetLongText(text string, err error) GetLongText

MockGetLongText mocks GetLongText function

type GetQuoteAuthor

type GetQuoteAuthor func(ctx context.Context, tweetArticleElement selenium.WebElement, hasTweetOnlyText bool) (string, error)

GetQuoteAuthor retrieves the quoted tweet author

func MakeGetQuoteAuthor

func MakeGetQuoteAuthor() GetQuoteAuthor

MakeGetQuoteAuthor creates a new GetQuoteAuthor

func MockGetQuoteAuthor

func MockGetQuoteAuthor(author string, err error) GetQuoteAuthor

MockGetQuoteAuthor mocks GetQuoteAuthor function

type GetQuoteAvatar

type GetQuoteAvatar func(ctx context.Context, tweetArticleElement selenium.WebElement, hasTweetOnlyText bool) (string, error)

GetQuoteAvatar retrieves the quote author's avatar

func MakeGetQuoteAvatar

func MakeGetQuoteAvatar() GetQuoteAvatar

MakeGetQuoteAvatar creates a new GetQuoteAvatar

func MockGetQuoteAvatar

func MockGetQuoteAvatar(avatar string, err error) GetQuoteAvatar

MockGetQuoteAvatar mocks GetQuoteAvatar function

type GetQuoteImages

type GetQuoteImages func(ctx context.Context, tweetArticleElement selenium.WebElement, isAReply, hasTweetOnlyText bool) ([]string, error)

GetQuoteImages retrieves the quoted tweet images

func MakeGetQuoteImages

func MakeGetQuoteImages() GetQuoteImages

MakeGetQuoteImages creates a new GetQuoteImages

func MockGetQuoteImages

func MockGetQuoteImages(urls []string, err error) GetQuoteImages

MockGetQuoteImages mocks GetQuoteImages function

type GetQuoteText

type GetQuoteText func(ctx context.Context, tweetArticleElement selenium.WebElement, isAReply, hasTweetOnlyText, hasTweetOnlyImages, isQuoteAReply bool) (string, error)

GetQuoteText retrieves the quoted tweet text

func MakeGetQuoteText

func MakeGetQuoteText() GetQuoteText

MakeGetQuoteText creates a new GetQuoteText

func MockGetQuoteText

func MockGetQuoteText(text string, err error) GetQuoteText

MockGetQuoteText mocks GetQuoteText function

type GetQuoteTimestamp

type GetQuoteTimestamp func(ctx context.Context, tweetArticleElement selenium.WebElement, hasTweetOnlyText bool) (string, error)

GetQuoteTimestamp retrieves the quoted tweet timestamp from the datetime attribute of the time element

func MakeGetQuoteTimestamp

func MakeGetQuoteTimestamp() GetQuoteTimestamp

MakeGetQuoteTimestamp creates a new GetQuoteTimestamp

func MockGetQuoteTimestamp

func MockGetQuoteTimestamp(timestamp string, err error) GetQuoteTimestamp

MockGetQuoteTimestamp mocks GetQuoteTimestamp function

type GetText

type GetText func(ctx context.Context, tweetArticleElement selenium.WebElement, isAReply bool) (string, bool, error)

GetText retrieves the tweet text

func MakeGetText

func MakeGetText() GetText

MakeGetText creates a new GetText

func MockGetText

func MockGetText(text string, hasLongText bool, err error) GetText

MockGetText mocks GetText function

type GetTimestamp

type GetTimestamp func(ctx context.Context, tweetArticleElement selenium.WebElement) (string, error)

GetTimestamp retrieves the tweet timestamp from the datetime attribute of the time element

func MakeGetTimestamp

func MakeGetTimestamp() GetTimestamp

MakeGetTimestamp creates a new GetTimestamp

func MockGetTimestamp

func MockGetTimestamp(timestamp string, err error) GetTimestamp

MockGetTimestamp mocks GetTimestamp function

type GetTweetInformation

type GetTweetInformation func(ctx context.Context, tweetArticleElement selenium.WebElement, tweetID string) (Tweet, error)

GetTweetInformation retrieves the tweet information from the given tweet element

func MakeGetTweetInformation

func MakeGetTweetInformation(isAReply IsAReply, getAuthor GetAuthor, getTimestamp GetTimestamp, getAvatar GetAvatar, getText GetText, getImages GetImages, hasQuote HasQuote, isQuoteAReply IsQuoteAReply, getQuoteAuthor GetQuoteAuthor, getQuoteAvatar GetQuoteAvatar, getQuoteTimestamp GetQuoteTimestamp, getQuoteText GetQuoteText, getQuoteImages GetQuoteImages, openAndRetrieveTweetArticleByID OpenAndRetrieveArticleByID, getLongText GetLongText, closeOpenedTabs page.CloseOpenedTabs) GetTweetInformation

MakeGetTweetInformation creates a new GetTweetInformation

func MockGetTweetInformation

func MockGetTweetInformation(tweet Tweet, err error) GetTweetInformation

MockGetTweetInformation mocks GetTweetInformation function

type HasQuote

type HasQuote func(tweetArticleElement selenium.WebElement, isAReply, hasTweetOnlyText bool) bool

HasQuote returns a bool indicating if the base tweet is quoting another tweet

func MakeHasQuote

func MakeHasQuote() HasQuote

MakeHasQuote creates a new HasQuote

func MockHasQuote

func MockHasQuote(hasQuote bool) HasQuote

MockHasQuote mocks HasQuote function

type IsAReply

type IsAReply func(tweetArticleElement selenium.WebElement) bool

IsAReply returns a bool indicating if the base tweet is replying to another tweet

func MakeIsAReply

func MakeIsAReply() IsAReply

MakeIsAReply creates a new GetIsAReply

func MockIsAReply

func MockIsAReply(isAReply bool) IsAReply

MockIsAReply mocks IsAReply function

type IsQuoteAReply

type IsQuoteAReply func(tweetArticleElement selenium.WebElement, isAReply, hasTweetOnlyText bool) bool

IsQuoteAReply returns a bool indicating if the quoted tweet is replying to another tweet

func MakeIsQuoteAReply

func MakeIsQuoteAReply() IsQuoteAReply

MakeIsQuoteAReply creates a new IsQuoteAReply

func MockIsQuoteAReply

func MockIsQuoteAReply(isQuoteAReply bool) IsQuoteAReply

MockIsQuoteAReply mocks IsQuoteAReply function

type OpenAndRetrieveArticleByID

type OpenAndRetrieveArticleByID func(ctx context.Context, author, id string) (selenium.WebElement, error)

OpenAndRetrieveArticleByID navigates into a specific tweet and retrieves the <article> HTML element associated with it. This allows us to extract the full text of tweets exceeding 280 characters (the limit for free accounts). The function ensures the retrieved <article> corresponds to the provided tweet ID, even if the tweet is part of a thread or accompanied by replies

func MakeOpenAndRetrieveArticleByID

func MakeOpenAndRetrieveArticleByID(openNewTab page.OpenNewTab, waitAndRetrieveElements elements.WaitAndRetrieveAll, getTweetIDFromTweetPage GetIDFromTweetPage) OpenAndRetrieveArticleByID

MakeOpenAndRetrieveArticleByID creates a new OpenAndRetrieveArticleByID

func MockOpenAndRetrieveArticleByID

func MockOpenAndRetrieveArticleByID(element selenium.WebElement, err error) OpenAndRetrieveArticleByID

MockOpenAndRetrieveArticleByID mocks OpenAndRetrieveArticleByID function

type Quote

type Quote struct {
	Data
}

Quote contains the information of a retweeted tweet in the original tweet

func MockQuote

func MockQuote(IsAReply, hasText, hasImages bool, text string, images []string) Quote

MockQuote mocks a Quote

func (Quote) String

func (quote Quote) String() string

String converts Quote properties to a string

type RetrieveAll

type RetrieveAll func(ctx context.Context) ([]Tweet, error)

RetrieveAll retrieves all the tweets from the current page

func MakeRetrieveAll

func MakeRetrieveAll(waitAndRetrieveElement elements.WaitAndRetrieve, waitAndRetrieveElements elements.WaitAndRetrieveAll, getTweetID GetID, getTweetInformation GetTweetInformation, scrollPage page.Scroll) RetrieveAll

MakeRetrieveAll creates a new RetrieveAll

func MockRetrieveAll

func MockRetrieveAll(tweets []Tweet, err error) RetrieveAll

MockRetrieveAll mocks RetrieveAll function

type Tweet

type Tweet struct {
	ID       string
	HasQuote bool
	Data
	Quote
}

Tweet contains the information needed to represent a tweet

func MockTweet

func MockTweet() Tweet

MockTweet mocks a Tweet

func (Tweet) String

func (tweet Tweet) String() string

String converts Tweet properties to a string

Jump to

Keyboard shortcuts

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