journalist

package
v1.3.47 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

}

func (*News) Contains

func (n *News) Contains(keywords []string) bool

type NewsList

type NewsList []*News

func (NewsList) ToContentJSON

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

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

func (NewsList) ToJSON

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

ToJSON returns the JSON of the news list.

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