Ejemplo n.º 1
0
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'
                           }
Ejemplo n.º 2
0
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'
                           }
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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'
                                             }
Ejemplo n.º 5
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'
                           }
Ejemplo n.º 6
0
 def test_fetch_by_feed(self):
     e = entry.Entry()
     rows = e.fetch_by_feed(2)
     self.assertGreater(len(rows), 3)
Ejemplo n.º 7
0
 def test_init_with_id(self):
     e = entry.Entry(28160)
     self.assertEqual(e.title, 'Death to America')
Ejemplo n.º 8
0
 def test_init(self):
     e = entry.Entry()
     self.assertEqual(e.ID, None)