Example #1
0
#!/usr/bin/env python
# coding=utf8

import os
from flask import Flask, render_template, request
from flask.ext.bootstrap import Bootstrap
import useragent

app = Flask(__name__)
Bootstrap(app)

app.config["BOOTSTRAP_USE_MINIFIED"] = True
app.config["BOOTSTRAP_USE_CDN"] = False
app.config["BOOTSTRAP_FONTAWESOME"] = True
app.config["BOOTSTRAP_GOOGLE_ANALYTICS_ACCOUNT"] = "UA-36835748-1"


@app.route("/")
def index():
    ua = useragent.detect(str(request.user_agent))
    os = detectOS(ua)
    return render_template("index.html")


@app.route("/about/")
def about():
    return render_template("about.html")


def detectOS(ua):
    os_string = ua.os.family.lower()
def conf(key, default=""):
    """Helper to load a configuration from `app.config`, if it
    exists, or from `os.environ` (and saving into `app.config`).
    """
    if key in app.config:
        return app.config[key]
    elif key in os.environ:
        app.config[key] = os.environ[key]
        return app.config[key]
    return default


app.secret_key = conf("FLASK_SECRET_KEY", "Bn1dcC2QDWXgtj")

app.config["BOOTSTRAP_GOOGLE_ANALYTICS_ACCOUNT"] = conf("BOOTSTRAP_GOOGLE_ANALYTICS_ACCOUNT")
Bootstrap(app)

oauth = OAuth()
meetup = oauth.remote_app(
    "meetup",
    base_url="https://api.meetup.com/",
    request_token_url="https://api.meetup.com/oauth/request/",
    access_token_url="https://api.meetup.com/oauth/access/",
    authorize_url="http://www.meetup.com/authorize/",
    consumer_key=conf("MEETUP_OAUTH_CONSUMER_KEY"),
    consumer_secret=conf("MEETUP_OAUTH_CONSUMER_SECRET"),
)

app.config["MONGO_URI"] = conf("MONGOHQ_URL", None)
mongo = PyMongo(app)