James Tombleson
ada453e08a
* updated db, added dto for ListSources, and added delete source * updated from model > models * updated to models * sources now sends back a standard message * updated subscription routes to have beter logid and swagger details * moved the dto objects back to modles given they are not bound to the database * cleaned up how we return the error * cleaned up swag and updated models to take from the base apistatusmodel. less human errors this way * cleaned up swag and updated models * swag updated * updated queue to return a router and also renamed it as it will hold all queue info later on * removed config tag * added subscription details route * article routes have been moved to support dto * updated discordwebhooks to use dto * updated discordwebhookqueue to return details on the items via dto * removed the example routes * updated sources to use dto * subscriptions moved to dto * generated swag
60 lines
1.0 KiB
Go
60 lines
1.0 KiB
Go
package input
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/jtom38/newsbot/collector/domain/models"
|
|
"github.com/jtom38/newsbot/collector/services/cache"
|
|
"github.com/mmcdole/gofeed"
|
|
)
|
|
|
|
type rssClient struct {
|
|
SourceRecord models.Sources
|
|
}
|
|
|
|
func NewRssClient(sourceRecord models.Sources) rssClient {
|
|
client := rssClient{
|
|
SourceRecord: sourceRecord,
|
|
}
|
|
|
|
return client
|
|
}
|
|
|
|
//func (rc rssClient) ReplaceSourceRecord(source model.Sources) {
|
|
//rc.SourceRecord = source
|
|
//}
|
|
|
|
func (rc rssClient) getCacheGroup() string {
|
|
return fmt.Sprintf("rss-%v", rc.SourceRecord.Name)
|
|
}
|
|
|
|
func (rc rssClient) GetContent() error {
|
|
feed, err := rc.PullFeed()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
cacheClient := cache.NewCacheClient(rc.getCacheGroup())
|
|
|
|
for _, item := range feed.Items {
|
|
log.Println(item)
|
|
|
|
cacheClient.FindByValue(item.Link)
|
|
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (rc rssClient) PullFeed() (*gofeed.Feed, error) {
|
|
feedUri := fmt.Sprintf("%v", rc.SourceRecord.Url)
|
|
fp := gofeed.NewParser()
|
|
feed, err := fp.ParseURL(feedUri)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return feed, nil
|
|
}
|