Exemple #1
0
func UpdateFeed(feed structure.Feed) {
	update, err := feedparser.ParseURL(feed.URL)
	utils.Checkerr(err)
	var link string
	for _, li := range update.Link {
		if li.Rel == "alternate" {
			link = li.Href
		}
	}
	if len(link) == 0 {
		link = update.Link[0].Href
	}
	meta, err := siteparser.GetMetaForSite(link)
	utils.Checkerr(err)
	err = db.UpdateFeedInformation(update.Title, update.Subtitle, meta.Icon, meta.TwitterSite, feed.URL, update.Updated)
	utils.Checkerr(err)
	var entries []structure.Entry
	for _, entry := range update.Entries {
		exists := false
		for _, oldentry := range feed.Entries {
			if strings.Compare(entry.ID, oldentry.ID) == 0 && entry.Updated.Equal(oldentry.Updated) {
				exists = true
			}
		}
		if !exists {
			newentry := convertAtomEntryToDBEntry(entry)
			entries = append(entries, newentry)
		}
	}
	err = db.UpdateFeedEntryList(entries, feed.URL)
	utils.Checkerr(err)
	feed, err = db.GetFeedByURL(feed.URL)
	utils.Checkerr(err)
	sortedentries := structure.SortEntriesByDate(feed.Entries)
	var occasions []time.Time
	for _, entry := range sortedentries {
		occasions = append(occasions, entry.Updated)
	}
	changefrequency := calculateChangeFrequency(occasions)
	err = db.UpdateFeedChangeFrequency(feed.URL, changefrequency)
	utils.Checkerr(err)
	err = db.UpdateFeedLastUpdate(feed.URL, time.Now())
	utils.Checkerr(err)
}
Exemple #2
0
func sortEntriesInFeed(feed structure.Feed) structure.Feed {
	feed.Entries = structure.SortEntriesByDate(feed.Entries)
	return feed
}