Example #1
0
func NewThumbnail(uri string, width, height uint) (filepath, mediatype string, w, h int, err error) {
	fp, mediatype, _, err := document.DefaultCurl().Download(uri)
	if err != nil {
		return
	}
	f, err := os.Open(fp)
	if err != nil {
		return
	}
	defer f.Close()
	img, mediatype, err := image.Decode(f)
	if err != nil {
		return
	}
	imgnew := resize.Resize(width, height, img, resize.MitchellNetravali)
	w = imgnew.Bounds().Max.X
	h = imgnew.Bounds().Max.Y

	of, err := ioutil.TempFile("", "")
	if err != nil {
		return
	}
	defer of.Close()
	err = jpeg.Encode(of, imgnew, &jpeg.Options{90})
	if err != nil {
		return
	}
	filepath = of.Name()
	return
}
Example #2
0
func fetch_entries(feds []meta.Feed, done chan<- int) {
	fmt.Println("fetch entries", len(feds))
	curl := d.DefaultCurl()
	for _, feed := range feds {
		rsfile, _, _, err := curl.Download(feed.Link)
		fmt.Println(rsfile, err)
		if err != nil {
			fmt.Println(err)
			continue
		}
		f, entries, err := feeds.NewFeed(rsfile, feed.Link)
		if err != nil {
			fmt.Println(feed.Link, len(entries), err)
			feeds.NewFeedOperator().Disable(feed.Link, true)
		} else {
			fmt.Println(f.Title, len(entries))
		}

		if err == nil {
			ins, _ := feeds.NewEntryOperator().Save2(entries)
			fmt.Println(len(ins), feed.Link)
		}

	}
	done <- 0
}
Example #3
0
func main() {
	flag.Parse()
	if *uri == "" {
		fmt.Println("opml-parser --uri http://diggreader/opml.xml")
	}
	tf, _, _, _ := d.DefaultCurl().Download(*uri)
	ols, _ := opml.NewOpml(tf)
	feeds.NewFeedOperator().Save(ols)
	fmt.Println(ols)
}
Example #4
0
func main() {
	defer catch_panic()
	flag.Parse()
	if len(*uri) == 0 {
		panic(errors.New("usage: subscribe --uri http://xome.rss2.xml"))
	}
	rsfile, _, _, _ := d.DefaultCurl().Download(*uri) //document.FetchUrl2(*uri)
	log.Println(rsfile)
	ch, _, _ := feeds.NewFeed(rsfile, *uri)
	log.Println(ch)
	feeds.NewFeedOperator().Upsert(ch)
}
Example #5
0
func subscribe_rss2(w http.ResponseWriter, r *http.Request) {
	defer func() {
		if err := recover(); err != nil {
			http.Error(w, err.(error).Error(), http.StatusBadGateway)
			fmt.Println(err)
		}
	}()

	r.ParseForm()
	url := r.FormValue("url")
	fmt.Println("fetching ", url)
	rss_file, _, _, _ := htmldoc.DefaultCurl().Download(url)
	fmt.Println("rss-file", rss_file)
	channel, _, _ := feeds.NewFeed(rss_file, url)
	feeds.NewFeedOperator().Upsert(channel)

	write_json(w, channel)
}