from datetime import datetime

from bottle import response, route, run
from rss2producer import RSS2Feed
import dataset


# copy pasted from scraper
TABLE = 'bandc_items'


@route('/')
def index():
    db = dataset.connect()  # uses DATABASE_URL
    table = db.load_table(TABLE)  # don't allow dataset to create the table
    feed = RSS2Feed(
        title='BandC',
        link='TODO',
        description='description todo',
    )
    results = table.find(_limit=50, order_by='-scraped_at')
    for row in results:
        feed.append_item(
            title=row['text'],
            link=row['url'],
            description=row['text'],
            pub_date=datetime.combine(row['date'], datetime.min.time()),
        )
    response.content_type = 'application/rss+xml'
    return feed.get_xml()


if __name__ == '__main__':
    run(host='localhost', port=8000, reloader=True)

@@ -42,16 +42,23 @@
 e import
+ abort,
  respons
@@ -171,16 +171,27 @@
 _items'%0A
+LIMIT = 50%0A
 %0A%0A@route
@@ -209,16 +209,78 @@
 ndex():%0A
+    return 'TODO'%0A%0A%0A@route('/%3Cslug%3E/')%0Adef feed_detail(slug):%0A
     db =
@@ -502,24 +502,107 @@
 odo',%0A    )%0A
+    filter_kwargs = %7B%7D%0A    if slug != 'all':%0A        filter_kwargs%5B'bandc'%5D = slug%0A
     results 
@@ -621,18 +621,21 @@
 (_limit=
-50
+LIMIT
 , order_
@@ -650,16 +650,33 @@
 aped_at'
+, **filter_kwargs
 )%0A    fo
@@ -807,32 +807,81 @@
 ion=row%5B'text'%5D,
+  # TODO%0A            # convert date into datetime
 %0A            pub
@@ -944,24 +944,90 @@
 ,%0A        )%0A
+    # TODO if no results, abort(404, 'No results for that BandC')%0A
     response

add N feeds for N BandCs