Example #1
0
File: app.py Project: sopnic/ybk
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging

from flask import Flask, render_template, request, jsonify
from flask.ext.basicauth import BasicAuth

from trademanager import TradeManager, tops, names

app = Flask(__name__)

app.config["BASIC_AUTH_USERNAME"] = "ybk369"
app.config["BASIC_AUTH_PASSWORD"] = "ybk888"

basic_auth = BasicAuth(app)
tm = TradeManager()


@app.route("/")
@basic_auth.required
def index():
    symbol = request.args.get("symbol", "100001")
    namedict = {i["username"]: i["name"] for i in tm.investors}
    return render_template("index.html", tops=tops, names=names, namedict=namedict, symbol=symbol)


@app.route("/update.ajax")
def update():
    symbol = request.args.get("symbol", "100001")
    tm.sync(symbol)
    if symbol not in tm.prices:
Example #2
0
#!/usr/bin/env python
#-*- encoding: utf-8

from flask import Flask, render_template, request, session
from flask_socketio import SocketIO, emit
from flask.ext.basicauth import BasicAuth
import sqlite3
import time
import json
import os
import re

host = Flask(__name__)
host.config["SECRET_KEY"] = os.urandom(10)
host.config["BASIC_AUTH_USERNAME"] = "admin"
host.config["BASIC_AUTH_PASSWORD"] = "password"
sock = SocketIO(host)
auth = BasicAuth(host)
os.environ["tz"] = "Asia/Taipei"

@host.route("/")
@host.route("/<int:serial_code>")
def main(serial_code=None):
    if serial_code == None:
        data = do_sql("select serial_id, title, unit, descript from Activity", ())
        ret = []
        for d in data:
            (serial_id, title, unit, descript) = d
            ret.append({"id": serial_id, "title": title, "unit": unit, "descript": descript})
        return render_template("show.html", act=ret)
    else:
Example #3
0
def compileBreadcrumbs(title):
    title = title.split("/")
    href = ""
    breadcrumbs = []
    for part in title:
        href += "/" + part
        breadcrumbs.append({"href": href, "part": part})
    return breadcrumbs


app = Flask(__name__)
app.config["SECRET_KEY"] = "MimirIsNotSecure"

if config.get("security", "password") != "":
    app.config["BASIC_AUTH_USERNAME"] = config.get("security", "username")
    app.config["BASIC_AUTH_PASSWORD"] = config.get("security", "password")
    app.config["BASIC_AUTH_REALM"] = "Mímir is password protected"
    app.config["BASIC_AUTH_FORCE"] = True
    BasicAuth(app)


@app.route("/app")
def onePageApp():
    return render_template("app.html", title="Mímir")


@app.route("/", methods=["GET", "POST"])
@app.route("/+<format>", methods=["GET", "POST"])
@app.route("/<path:filename>", methods=["GET", "POST"])
@app.route("/<path:filename>+<format>", methods=["GET", "POST"])
def fmt_state_full(value):
    return constants.states[value.upper()]


# If HTTPS is on, apply full HSTS as well, to all subdomains.
# Only use when you're sure. 31536000 = 1 year.
if config.force_https:
    sslify = SSLify(app, permanent=True, age=31536000, subdomains=True)


if config.environment in ["stage", "prod"]:
    app.config["PREFERRED_URL_SCHEME"] = "https"


# Note: Apply basic auth check after HTTPS redirect so that users aren't prompted
# for credentials over HTTP; h/t @noahkunin.
if config.username and config.password:
    app.config["BASIC_AUTH_USERNAME"] = config.username
    app.config["BASIC_AUTH_PASSWORD"] = config.password
    app.config["BASIC_AUTH_FORCE"] = True
    basic_auth = BasicAuth(app)


app.wsgi_app = utils.ReverseProxied(app.wsgi_app)
app.wsgi_app = ProxyFix(app.wsgi_app)


if __name__ == "__main__":
    files = ["./rev-manifest.json"]
    app.run(host=config.host, port=int(config.port), debug=config.debug, extra_files=files)
Example #5
0
DEBUG = False
PORT = 5555
USERNAME = "PyMPL"
PASSWORD = "Password"

if __name__ == "__main__":
    if len(sys.argv) >= 2 and sys.argv[1].isdigit():
        PORT = int(sys.argv[1])

    if len(sys.argv) >= 3:
        PASSWORD = sys.argv[2]

app = Flask(__name__)
app.debug = True
app.config["BASIC_AUTH_USERNAME"] = USERNAME
app.config["BASIC_AUTH_PASSWORD"] = PASSWORD
app.config["BASIC_AUTH_FORCE"] = True
basic_auth = BasicAuth(app)
limiter = Limiter(app, global_limits=["50/minute", "5/second"])


@app.context_processor
def inject_globals():
    """Send global data to the template."""
    data = dict(
        app_name="PyMPL App",
        pages=[
            ("/pympl", "PyMPL"),
        ],
    )