def channel(channel_id): channel = db.session.query(Channel).get(channel_id) if not channel: flask.abort(404) url, name = channel.feed.split('|') feed = Feed(url, name) feed.parse() return flask.render_template('channel.html', feed=feed, channel=channel)
def guide(): channels = db.session.query(Channel).all() feeds = [] for channel in channels: url, name = channel.feed.split('|') feed = Feed(url, name) feed.parse() feed.channel = channel.name feeds.append(feed) return flask.render_template('guide.html', feeds=feeds)
def display_feed(feed_name): if feed_name not in config['feeds']: abort(404) f = Feed(config['feeds'][feed_name]) f.load() f.parse() fg = FeedGenerator() fg.generator(**_generator) fg.id(request.base_url) fg.link( href=request.base_url, rel='self', ) fg.title(f.properties.get('title', feed_name)) fg.author(name=f.properties.get('author', '')) fg.updated( timezone.localize( _round_date(max([e['updated'] for e in f.entries]), config.get('date_rounding', None)))) for entry in f.entries: fe = fg.add_entry() fe.id(entry['url']) fe.title(entry['title']) fe.link(href=entry['url']) fe.updated( timezone.localize( _round_date(entry['updated'], config.get('date_rounding', None)))) fe.content(entry['content']) atomfeed = fg.atom_str() resp = make_response(atomfeed) resp.headers['content-type'] = 'application/xml' return resp
import os import logging from feed import Feed from feedsources import FeedSources def init_logging(): logfile = 'fetcher.log' if os.path.isfile(logfile): os.remove(logfile) logging.basicConfig(filename=logfile, level=logging.DEBUG) logger = logging.getLogger('') console = logging.StreamHandler() console.setLevel(logging.INFO) logger.addHandler(console) if __name__ == '__main__': init_logging() feedsources = FeedSources() feedsources.read('feeds.yml') for url in feedsources.urls: feed = Feed() feed.parse(url) entries = feed.entries for entry in entries: print (entry)