예제 #1
0
파일: worker.go 프로젝트: hygerth/brooklet
func convertAtomEntryToDBEntry(entry feedparser.Entry) structure.Entry {
	var newentry structure.Entry
	newentry.Title = entry.Title
	newentry.Summary = entry.Summary
	if len(entry.Summary) >= len(entry.Content) {
		article, err := siteparser.GetArticleForSite(entry.Link.Href)
		utils.Checkerr(err)
		if len(article) > 0 && len(article) > len(entry.Summary) {
			newentry.Content = article
		} else {
			newentry.Content = entry.Summary
		}
	} else {
		newentry.Content = entry.Content
	}
	newentry.ID = entry.ID
	newentry.Updated = entry.Updated
	if !entry.GUID.IsPermaLink && len(entry.GUID.Content) > 0 {
		newentry.PermaLink = entry.GUID.Content
	} else {
		newentry.PermaLink = entry.Link.Href
	}
	newentry.Author = entry.Author.Name
	meta, err := siteparser.GetMetaForSite(newentry.PermaLink)
	if err != nil {
		newentry.PermaLink = entry.Link.Href
		meta, err = siteparser.GetMetaForSite(entry.Link.Href)
	}
	utils.Checkerr(err)
	newentry.Twitter = meta.TwitterCreator
	newentry.ArticleID = createNewID()
	hasImage, isPortrait, err := SyncImage(meta.Image, newentry.ArticleID)
	utils.Checkerr(err)
	newentry.HasImage = hasImage
	switch isPortrait {
	case false:
		newentry.ImageRotation = "landscape"
	default:
		newentry.ImageRotation = "portrait"
	}
	return newentry
}
예제 #2
0
파일: worker.go 프로젝트: hygerth/brooklet
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)
}