-
Notifications
You must be signed in to change notification settings - Fork 1
/
twitter_rss.py
37 lines (25 loc) · 1.11 KB
/
twitter_rss.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import logging.handlers
from flask import Flask, request, Response, url_for, current_app, redirect
from werkzeug.contrib.atom import AtomFeed
from parser import get_tweets, get_title, get_body, get_url, get_icon
app = Flask(__name__)
app.config.from_object('settings')
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.INFO)
app.logger.addHandler(stream_handler)
smtp_handler = logging.handlers.SMTPHandler(**app.config['ERROR_EMAIL'])
smtp_handler.setLevel(logging.ERROR)
app.logger.addHandler(smtp_handler)
@app.route('/')
def home():
return redirect(url_for('feed'))
@app.route('/timeline.atom')
def feed():
feed = AtomFeed(app.config.get('FEED_TITLE') or 'twitter', feed_url=request.url, url=request.url_root, icon=url_for('favicon'))
for tweet in get_tweets(current_app.config):
feed.add(title=get_title(tweet), content=get_body(tweet), content_type='html', url=get_url(tweet),
published=tweet.created_at, updated=tweet.created_at)
return feed.get_response()
@app.route('/favicon.ico')
def favicon():
return Response(get_icon(), mimetype='image/x-icon')