journalist

package
v1.9.8 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error added in v1.5.0

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

Error is the error type for the Journalist.

func (*Error) Error added in v1.5.0

func (e *Error) Error() string

func (*Error) Unwrap added in v1.5.1

func (e *Error) Unwrap() error

func (*Error) WithProvider added in v1.5.0

func (e *Error) WithProvider(providerName string) *Error

type Journalist

type Journalist struct {
	Name string // Name of the journalist (for logging purposes)
	// contains filtered or unexported fields
}

Journalist is the main struct that fetches the news from all providers and merges them into unified list.

func NewJournalist

func NewJournalist(name string, providers []NewsProvider) *Journalist

NewJournalist creates a new Journalist instance.

func (*Journalist) FlagByKeys

func (j *Journalist) FlagByKeys(flagKeys []string) *Journalist

FlagByKeys sets the keys that will "flag" news that contain them by setting News.IsSuspicious to true.

func (*Journalist) GetLatestNews

func (j *Journalist) GetLatestNews(ctx context.Context, until time.Time) (NewsList, error)

GetLatestNews fetches the latest news (until date) from all providers and merges them into unified list.

func (*Journalist) Limit

func (j *Journalist) Limit(limit int) *Journalist

Limit sets the limit of news to fetch from each provider.

type News

type News struct {
	ID           string    // ID is the md5 hash of title + description
	Title        string    // Title is the title of the news
	Description  string    // Description is the description of the news
	Link         string    // Link is the link to the news
	Date         time.Time // Date is the date of the news
	ProviderName string    // ProviderName is the Name of the provider that fetched the news
	IsSuspicious bool      // IsSuspicious is true if the news contains keywords that should be checked by human before publishing
	IsFiltered   bool      // IsFiltered is true if the news was filtered out by others service (e.g. Composer.Filter)

}

type NewsList

type NewsList []*News

func (NewsList) RemoveFlagged added in v1.7.0

func (n NewsList) RemoveFlagged() NewsList

RemoveFlagged returns a new NewsList without the flagged (IsFiltered, IsSuspicious) news.

func (NewsList) ToContentJSON

func (n NewsList) ToContentJSON() (string, error)

ToContentJSON returns the JSON of the news content only: id, title, description.

type NewsProvider

type NewsProvider interface {
	Fetch(ctx context.Context, until time.Time) (NewsList, error)
}

NewsProvider is the interface for the data fetcher (via RSS, API, etc.).

type RssProvider

type RssProvider struct {
	Name string // Name is used for logging purposes
	URL  string
}

RssProvider is the RSS provider implementation.

func NewRssProvider

func NewRssProvider(name, url string) *RssProvider

NewRssProvider creates a new RssProvider instance.

func (*RssProvider) Fetch

func (r *RssProvider) Fetch(ctx context.Context, until time.Time) (NewsList, error)

Fetch fetches the news from the RSS feed until the given date.

Jump to

Keyboard shortcuts

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