This repository has been archived by the owner on Aug 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
batman_app.py
86 lines (72 loc) · 2.79 KB
/
batman_app.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from flask import Flask, request, session, g, redirect, url_for, abort, \
render_template, flash
from flaskext.sqlalchemy import SQLAlchemy
from flaskext.xmlrpc import XMLRPCHandler, Fault
from batman.local_settings import DATABASE_LOCATION
from batman.models import FloorDate, FloorEvent
import PyRSS2Gen as pyrss
import datetime
DEBUG = True
SECRET_KEY = 'test'
#init app
app = Flask(__name__)
app.secret_key = SECRET_KEY
app.debug = DEBUG
app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_LOCATION
#db settings
db = SQLAlchemy()
db.init_app(app)
@app.route('/house')
def house_feed():
rss_items = []
for day in FloorDate.query.all():
day_item = pyrss.RSSItem(
title = str(day.proceeding_date),
link = day.mp4_url,
description = "Legislative Day %s" % day.proceeding_date,
guid = pyrss.Guid(day.mp4_url),
pubDate = str(day.add_date),
)
rss_items.append(day_item)
rss = pyrss.RSS2(
title = "HouseLive.gov Video",
link = "http://batman.sunlightlabs.com/house",
description = "HouseLive.gov Video Feed",
lastBuildDate = datetime.datetime.now(),
items = rss_items
)
return rss.to_xml()
@app.route('/house/day/<day>')
def house_day_feed(day):
rss_items = []
proceeding = FloorDate.query.get(day)
events = FloorEvent.query.filter_by(proceeding=day).order_by('timestamp')
for e in events:
weights = events.filter_by(timestamp=e.timestamp).order_by('weight')
text = []
for w in weights:
text.append(w.description)
event_item = pyrss.RSSItem(
title = "%s - %s" % (proceeding.proceeding_date, e.timestamp),
link = "%s#%s" % (proceeding.mp4_url, e.offset),
description = ''.join(text),
pubDate = str(proceeding.add_date),
)
rss_items.append(event_item)
rss = pyrss.RSS2(
title = 'HouseLive.gov Video for %s' % proceeding.proceeding_date,
link = "http://batman.sunlightlabs.com/house/day/%s" % day,
description = 'HouseLive.gov Video',
lastBuildDate = "%s" % proceeding.add_date,
items = rss_items
)
return rss.to_xml()
@app.route('/')
def home():
my_str = ''
for fd in FloorDate.query.all():
my_str += '\n' + str(fd.clip_id)
return my_str
return 'test'
if __name__ == '__main__':
app.run()