def recent(): """ Grabs x entries from the stash starting at pos y sorted chronological newest on top """ amount, start = amountstart() f = Feed.Feed() recents = f.get_recents(amount=amount, start=start) feeds = {} for feedid, entryid in recents: if not feeds.get('feed%s' % feedid, None): feeds['feed%s' % feedid] = Feed.Feed(feedid) feeds['feed%s' % feedid].entries.append(Entry.Entry(entryid)) return render_template("recent.html", feeds=feeds.values(), amount=amount, menu=usermenu(), nextstart=int(start) + int(amount), path='/recent', prevstart=max(int(start) - int(amount), -1)), 200, { 'Cache-Control': 's-maxage=10' }
def userbookmarks(username): if not username: return redirect('/recent', 302) user = User.User(username=username) if user.ID: amount, start = amountstart() b = Bookmark.Bookmark() bookmarks = b.get_bookmarks(userID=user.ID, amount=amount, start=start) f = Feed.Feed() feedentries = f.get_by_bookmarks(bookmarks) if f.get_by_bookmarks( bookmarks) else [] feeds = {} for feedid, entryid, d in feedentries: if not feeds.get('feed%s' % feedid, None): feeds['feed%s' % feedid] = Feed.Feed(feedid) feeds['feed%s' % feedid].entries.append(Entry.Entry(entryid)) return render_template("recent.html", feeds=feeds.values(), amount=amount, menu=usermenu(), title='Bookmarks by: %s' % username, path="/%s/bookmarks" % username, nextstart=int(start) + int(amount), prevstart=max(int(start) - int(amount), -1)), 200, { 'Cache-Control': 's-maxage=1' }
def search(): amount, start = amountstart() tokens = request.args.get('q', '') if not tokens: return recent() e = Entry.Entry() hits = e.search(tokens, amount=amount, start=start) feeds = {} for feedid, entryid, d, score in hits: if not feeds.get('feed%s' % feedid, None): feeds['feed%s' % feedid] = Feed.Feed(feedid) feeds['feed%s' % feedid].entries.append(Entry.Entry(entryid)) return render_template("recent.html", feeds=feeds.values(), amount=amount, menu=usermenu(), title='Search: %s' % tokens, path="/search", extraarg="&q=%s" % tokens, nextstart=int(start) + int(amount), prevstart=max(int(start) - int(amount), -1), tokens=tokens, totresults=e.searchamount(q=tokens)), 200, { 'Cache-Control': 's-maxage=1' }
def send_digest(): digestables = Group.Group().get_digestables() for groupid in digestables: group = Group.Group(groupid) user = User.User(group.userID) digestable = group.get_digestable() if not digestable: continue feeds = {} for feedid, entryid in digestable: if not feeds.get('feed%s' % feedid, None): feeds['feed%s' % feedid] = Feed.Feed(feedid) feeds['feed%s' % feedid].entries.append(Entry.Entry(entryid)) html = render_template("email.html", feeds=feeds.values(), group=group) # Create message container - the correct MIME type is multipart/alternative. msg = MIMEMultipart('alternative') msg['Subject'] = "Email digest: %s (issue: %s)" % (group.description, group.issue) msg['From'] = '*****@*****.**' msg['To'] = user.email text = 'switch to html' msg.attach(MIMEText(text, 'plain')) msg.attach(MIMEText(html, 'html')) s = smtplib.SMTP('localhost') s.sendmail(msg['From'], msg['To'], msg.as_string()) s.quit() group.update_sent() print('sent digest to: %s. %s' % (user.email, group.description)) return ('', 204)
def do_feed(identifier=None, outputtype='html'): """ Get one feed from the database. grab @amount (int default: 10) of entries starting at position @start (int default: 0) add /xml to the path to get a rss feed generated here """ if outputtype not in ['html', 'xml']: abort(404) template = 'feed.html' if outputtype == 'html' else 'rss.html' amount, start = amountstart() menu = usermenu() if int(identifier): feed = Feed.Feed(int(identifier)) else: feed = None # TODO: init_by_url (init_by('url', identifier) zoiets) # fill it feed.with_entries(amount=amount, start=start) payload = render_template(template, feed=feed, menu=menu, amount=amount, nextstart=int(start) + int(amount), prevstart=max(int(start) - int(amount), -1)) if outputtype == 'html': return payload, 200, {'Cache-Control': 's-maxage=10'} return payload, 200, { 'Content-Type': 'text/xml; charset=utf-8', 'Cache-Control': 's-maxage=300' }
def feedlist(): groupid = request.args.get('groupid', None) if groupid: group = Group.Group(int(groupid)) feedids = [feed.ID for feed in group.feeds] else: group = Group.Group(description='Unknonw group') feedids = [] f_ids = Feed.Feed().get_all() feeds = [Feed.Feed(id) for id in f_ids] return render_template('widget/feedlist.html', feeds=feeds, group=group, feedids=feedids), 200, { 'Cache-Control': 's-maxage=0' }
def show_group(groupid): if not groupid: return redirect('/recent', 302) group = Group.Group(ID=int(groupid)) if not group.ID: return redirect('/recent', 302) amount, start = amountstart() recents = group.get_recents(amount=amount, start=start) feeds = {} for feedid, entryid in recents: if not feeds.get('feed%s' % feedid, None): feeds['feed%s' % feedid] = Feed.Feed(feedid) feeds['feed%s' % feedid].entries.append(Entry.Entry(entryid)) return render_template("recent.html", feeds=feeds.values(), amount=amount, menu=usermenu(), title='Grouped feeds: %s' % group.description, nextstart=int(start) + int(amount), path='/group/%s' % groupid, prevstart=max(int(start) - int(amount), -1)), 200, { 'Cache-Control': 's-maxage=30' }
import model.feed as Feed import config import time import sys print("|+-+ Harvesting @ %s +-+-+-+-+-+-+-+|" % time.strftime("%c")) feed = Feed.Feed() feed.harvest_all()
def all_feeds(): feed = Feed.Feed() feeds = [Feed.Feed(f) for f in feed.get_all()] return render_template("menu/feedlink.html", feeds=feeds)
def create_feed(): feed = Feed.Feed() new = feed.create(url=request.form.get('url')) return jsonify({'id': new.ID, 'url': new.url, 'title': new.title})
def maint_feed(id): f = Feed.Feed(int(id)) return render_template("settings/feed.html", feed=f)
def test_get_all(self): f = feed.Feed() self.assertGreater(len(f.get_all()), 2)
def test_with_entries(self): f = feed.Feed(2) f.with_entries() self.assertGreater(len(f.entries), 2)
def test_init_with_id(self): f = feed.Feed(2) self.assertEqual(f.url, 'https://www.nrc.nl/rss/')
def test_init(self): f = feed.Feed() self.assertEqual(f.ID, None)