www-main/main.py

31 lines
889 B
Python

import feedparser
from flask import Flask, render_template
from time import mktime
from datetime import datetime
app = Flask('main')
app.config.from_pyfile('main.cfg')
def pull_feed_entries():
all_entries = []
for tag, url in app.config['FEEDS']:
entries = feedparser.parse(url).entries
for e in entries:
e.tag = tag
dt = datetime.fromtimestamp(mktime(e.updated_parsed))
e.updated_display = dt.strftime(app.config['DATE_FORMAT'])
all_entries.extend(entries)
all_entries.sort(key=lambda e: e.updated_parsed, reverse=True)
return all_entries[:app.config['MAX_ENTRIES']]
@app.route('/')
def main():
return render_template('main.html', entries=pull_feed_entries())
@app.route('/about')
def about():
return render_template('about.html')
if __name__ == '__main__':
app.run('0.0.0.0', 8080, debug=True)