James Tombleson
ff4075383a
* added a route to delete subscriptions based on the ID given * added a new route to find a record based on the name and source * added a route to query Discord Web Hooks by Server and Channel names * tested the endpoints and they seem good to test more * updated some routes for subscriptions and formatted files * removed debug file * fixing some panic calls * swag
60 lines
1.0 KiB
Go
60 lines
1.0 KiB
Go
package input
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/jtom38/newsbot/collector/domain/model"
|
|
"github.com/jtom38/newsbot/collector/services/cache"
|
|
"github.com/mmcdole/gofeed"
|
|
)
|
|
|
|
type rssClient struct {
|
|
SourceRecord model.Sources
|
|
}
|
|
|
|
func NewRssClient(sourceRecord model.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
|
|
}
|