package journalist
import "github.com/samgozman/fin-thread/journalist"
Index
Types
type Error
type Error struct { // contains filtered or unexported fields }
Error is the error type for the Journalist.
func (*Error) Error
func (e *Error) Error() string
func (*Error) Unwrap
func (e *Error) Unwrap() error
func (*Error) WithProvider
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
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.