Esempio n. 1
0
func apiLatestHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, xml.Header)
	enc := xml.NewEncoder(w)
	feeds, _ := db.GetAllFeeds()
	entries := structure.ExtractEntriesFromFeeds(feeds...)
	filter, _ := db.GetFilter()
	entries = structure.FilterEntries(entries, filter)
	atomfeed := atom.CreateAtomFeed("Latest", "The latest news from your Brooklet subscriptions", "latestbrooklet", "Brooklet", "", time.Now())
	for _, entry := range entries {
		atomfeed.AddEntry(entry.Title, entry.Summary, entry.Content, entry.ID, entry.ID, entry.PermaLink, entry.Author, entry.Twitter, entry.Updated)
	}
	enc.Encode(atomfeed)
}
Esempio n. 2
0
func apiFeedHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, xml.Header)
	enc := xml.NewEncoder(w)
	vars := mux.Vars(r)
	name := vars["name"]
	feed, _ := db.GetFeedByName(name)
	entries := structure.ExtractEntriesFromFeeds(feed)
	filter, _ := db.GetFilter()
	entries = structure.FilterEntries(entries, filter)
	atomfeed := atom.CreateAtomFeed(feed.Title, feed.Subtitle, feed.Name, feed.Title, feed.Twitter, feed.Updated)
	for _, entry := range entries {
		atomfeed.AddEntry(entry.Title, entry.Summary, entry.Content, entry.ID, entry.ID, entry.PermaLink, entry.Author, entry.Twitter, entry.Updated)
	}
	enc.Encode(atomfeed)
}
Esempio n. 3
0
func (c *Cache) SetAll() {
	c.lock.Lock()
	defer c.lock.Unlock()
	feeds, _ := db.GetAllFeeds()
	entries := structure.ExtractEntriesFromFeeds(feeds...)
	filter, _ := db.GetFilter()
	entries = structure.FilterEntries(entries, filter)
	if len(entries) > 100 {
		entries = entries[:100]
	}
	var d Data
	d.timestamp = time.Now()
	d.Title = "All"
	d.Entries = entries
	c.data["all"] = d
}
Esempio n. 4
0
func (c *Cache) Set(key string) {
	log.Printf("brooklet: Adding '%s' to cache\n", key)
	if key == "all" {
		c.SetAll()
		return
	}
	c.lock.Lock()
	defer c.lock.Unlock()
	feed, _ := db.GetFeedByName(key)
	entries := structure.ExtractEntriesFromFeeds(feed)
	filter, _ := db.GetFilter()
	entries = structure.FilterEntries(entries, filter)
	if len(entries) > 100 {
		entries = entries[:100]
	}
	var d Data
	d.timestamp = time.Now()
	d.Title = feed.Title
	d.Entries = entries
	c.data[key] = d
}