<commit_before>package rss

import (
	"strings"

	"github.com/PuerkitoBio/goquery"
	log "github.com/Sirupsen/logrus"
)

func getImageRss1(item rss1_0Item) string {
	for _, enc := range item.Enclosures {
		if strings.Contains(enc.Type, "image") {
			return enc.Url
		}
	}

	doc, err := goquery.NewDocument(item.Link)
	if err != nil {
		log.Warnf("can not parse url %v", item.Link)
		return ""
	}

	selection := doc.Find(`meta[property="og:image"]`)
	if selection != nil {
		if imgURL, found := selection.Attr("content"); found {
			return imgURL
		}
	}

	selection = doc.Find(`meta[property="twitter:image"]`)
	if selection != nil {
		if imgURL, found := selection.Attr("content"); found {
			return imgURL
		}
	}

	return ""
}

func getSummaryRss1(item rss1_0Item) string {
	if !strings.ContainsAny(item.Description, "&lt;&gt;") {
		return item.Description
	}
	doc, err := goquery.NewDocument(item.Link)
	if err != nil {
		log.Warnf("can not parse url %v", item.Link)
		return ""
	}
	selection := doc.Find(`meta[property="og:description"]`)
	if selection != nil {
		if desc, found := selection.Attr("content"); found {
			return desc
		}
	}

	selection = doc.Find(`meta[property="twitter:description"]`)
	if selection != nil {
		if desc, found := selection.Attr("content"); found {
			return desc
		}
	}

	return ""
}

func getImageRss2(item rss2_0Item) string {
	for _, enc := range item.Enclosures {
		if strings.Contains(enc.Type, "image") {
			return enc.Url
		}
	}
	doc, err := goquery.NewDocument(item.Link)
	if err != nil {
		log.Warnf("can not parse url %v", item.Link)
		return ""
	}

	selection := doc.Find(`meta[property="og:image"]`)
	if selection != nil {
		if imgURL, found := selection.Attr("content"); found {
			return imgURL
		}
	}

	selection = doc.Find(`meta[property="twitter:image"]`)
	if selection != nil {
		if imgURL, found := selection.Attr("content"); found {
			return imgURL
		}
	}

	return ""
}

func getSummaryRss2(item rss2_0Item) string {
	if !strings.ContainsAny(item.Description, "&lt;&gt;") {
		return item.Description
	}
	doc, err := goquery.NewDocument(item.Link)
	if err != nil {
		log.Warnf("can not parse url %v", item.Link)
		return ""
	}
	selection := doc.Find(`meta[property="og:description"]`)
	if selection != nil {
		if desc, found := selection.Attr("content"); found {
			return desc
		}
	}

	selection = doc.Find(`meta[property="twitter:description"]`)
	if selection != nil {
		if desc, found := selection.Attr("content"); found {
			return desc
		}
	}

	return ""
}
<commit_msg>give preference to og and twitter descriptions<commit_after>package rss

import (
	"strings"

	"github.com/PuerkitoBio/goquery"
	log "github.com/Sirupsen/logrus"
)

func getImageRss1(item rss1_0Item) string {
	for _, enc := range item.Enclosures {
		if strings.Contains(enc.Type, "image") {
			return enc.Url
		}
	}

	doc, err := goquery.NewDocument(item.Link)
	if err != nil {
		log.Warnf("can not parse url %v", item.Link)
		return ""
	}

	selection := doc.Find(`meta[property="og:image"]`)
	if selection != nil {
		if imgURL, found := selection.Attr("content"); found {
			return imgURL
		}
	}

	selection = doc.Find(`meta[property="twitter:image"]`)
	if selection != nil {
		if imgURL, found := selection.Attr("content"); found {
			return imgURL
		}
	}

	return ""
}

func getSummaryRss1(item rss1_0Item) string {
	doc, err := goquery.NewDocument(item.Link)
	if err != nil {
		log.Warnf("can not parse url %v", item.Link)
		return ""
	}
	selection := doc.Find(`meta[property="og:description"]`)
	if selection != nil {
		if desc, found := selection.Attr("content"); found {
			return desc
		}
	}

	selection = doc.Find(`meta[property="twitter:description"]`)
	if selection != nil {
		if desc, found := selection.Attr("content"); found {
			return desc
		}
	}

	if !strings.ContainsAny(item.Description, "&lt;&gt;") {
		return item.Description
	}

	return ""
}

func getImageRss2(item rss2_0Item) string {
	for _, enc := range item.Enclosures {
		if strings.Contains(enc.Type, "image") {
			return enc.Url
		}
	}
	doc, err := goquery.NewDocument(item.Link)
	if err != nil {
		log.Warnf("can not parse url %v", item.Link)
		return ""
	}

	selection := doc.Find(`meta[property="og:image"]`)
	if selection != nil {
		if imgURL, found := selection.Attr("content"); found {
			return imgURL
		}
	}

	selection = doc.Find(`meta[property="twitter:image"]`)
	if selection != nil {
		if imgURL, found := selection.Attr("content"); found {
			return imgURL
		}
	}

	return ""
}

func getSummaryRss2(item rss2_0Item) string {
	doc, err := goquery.NewDocument(item.Link)
	if err != nil {
		log.Warnf("can not parse url %v", item.Link)
		return ""
	}
	selection := doc.Find(`meta[property="og:description"]`)
	if selection != nil {
		if desc, found := selection.Attr("content"); found {
			return desc
		}
	}

	selection = doc.Find(`meta[property="twitter:description"]`)
	if selection != nil {
		if desc, found := selection.Attr("content"); found {
			return desc
		}
	}
	if !strings.ContainsAny(item.Description, "&lt;&gt;") {
		return item.Description
	}

	return ""
}

{'fraction_non_alphanumeric': 0.1599214145383104, 'fraction_numerical': 0.004715127701375246, 'mean_word_length': 3.867112810707457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4835400', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1784, 'n_words': 412}