Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added listeners table and make sure we get the right request ip.

  • Loading branch information...
commit 9178bb1312f06c45b3e91506ee12cf4f53bf74c3 1 parent 8487490
@toots toots authored
View
7 liqflows.py
@@ -10,9 +10,16 @@
from urlparse import urlparse
from datetime import datetime,timedelta
from flask import Flask,request,g
+# load the middleware from werkzeug
+# This middleware can be applied to add HTTP proxy support to an application
+# that was not designed with HTTP proxies in mind.
+# It sets `REMOTE_ADDR`, `HTTP_POST` from `X-Forwarded` headers.
+from werkzeug.contrib.fixers import ProxyFix
from schema.model import User, Radio, Stream
app = Flask(__name__)
+app.wsgi_app = ProxyFix(app.wsgi_app)
+
# Parse query string
def q(p):
View
1  requirements.txt
@@ -1,5 +1,6 @@
gunicorn==0.13.4
Flask==0.8
+Werkzeug==0.8.2
psycopg2==2.4.2
SQLAlchemy==0.7.3
sqlalchemy-migrate==0.7.2
View
21 schema/model.py
@@ -84,6 +84,7 @@ class Stream(Base):
format = Column(Text, NonEmptyConstraint('format'), nullable=False)
url = Column(Text, NonEmptyConstraint('url'), nullable=False)
msg = Column(Text)
+ listeners = relationship('Listener', collection_class=set, backref=backref('stream'), cascade='all, delete-orphan')
def __init__(self, **args):
if (not 'radio' in args) or args['radio'] == None:
@@ -96,9 +97,29 @@ def __init__(self, **args):
Base.__init__(self, **args)
# Do not export "radio", "streams" is already exported there..
+ # Also do not export listeners..
def export(self):
data = { "format" : self.format, "url" : self.url }
if self.msg != None and self.msg != "":
data["msg"] = self.msg
return data
+
+class Listener(Base):
+ __tablename__ = 'listeners'
+ id = Column(Integer, primary_key=True)
+ stream_id = Column(Integer, ForeignKey(Stream.id))
+ longitude = Column(Float)
+ latitude = Column(Float)
+ ip = Column(Text, nullable=False)
+ last_seen = Column(DateTime, nullable=False)
+
+ def __init__(self, **args):
+ if (not 'stream' in args) or args['stream'] == None:
+ raise Exception("No stream given!")
+ if (not 'ip' in args) or args['ip'] == None or args['ip'] == "":
+ raise Exception("No ip given!")
+ if (not 'last_seen' in args) or args['last_seen'] == None or args['last_seen'] == "":
+ args['last_seen'] = datetime.today()
+
+ Base.__init__(self, **args)
View
28 versions/009_add_listeners_table.py
@@ -0,0 +1,28 @@
+from sqlalchemy import *
+from migrate import *
+
+meta = MetaData()
+
+streams = Table('streams', meta,
+ Column('id', Integer, primary_key=True)
+)
+
+listeners = Table('listeners', meta,
+ Column('id', Integer, primary_key=True),
+ Column('stream_id', Integer, ForeignKey(streams.c.id)),
+ Column('longitude', Float),
+ Column('latitude', Float),
+ Column('ip', Text, nullable=False),
+ Column('last_seen', DateTime, nullable=False)
+)
+
+def upgrade(migrate_engine):
+ meta.bind = migrate_engine
+
+ listeners.create()
+
+
+def downgrade(migrate_engine):
+ meta.bind = migrate_engine
+
+ listeners.drop()
Please sign in to comment.
Something went wrong with that request. Please try again.