Example #1
0
from flask import Flask, jsonify
from flaskext.cache import Cache

from vanity import downloads_total


app = Flask(__name__)

# Support Heroku's Redis environment.
p = urlparse(os.environ.get("REDISTOGO_URL", ""))

app.config["CACHE_TYPE"] = "redis"
app.config["CACHE_REDIS_HOST"] = p.hostname or "localhost"
app.config["CACHE_REDIS_PORT"] = p.port or 6379
app.config["CACHE_REDIS_PASSWORD"] = p.password or None

cache = Cache(app)


@app.route("/")
def index():
    d = {
        "resources": {"/pypi/:package": "Given package's download stats."},
        "source": "https://github.com/kennethreitz/vaincheese",
    }
    return jsonify(d)


def total_downloads(package):
    count = downloads_total(package)
Example #2
0
LOG = getLogger(__name__)
Q = Queue()

app = Flask(__name__, static_folder=__file_path + "/static", static_path=SITE_ROOT + "/static")
app.url_map.converters["re"] = RegexConverter

if "REDIS_TO_GO" in os.environ:
    import urlparse

    urlparse.uses_netloc.append("redis")
    url = urlparse.urlparse(os.environ["REDIS_TO_GO"])
    app.config.from_envvar("REDIS_TO_GO")
    app.config["CACHE_TYPE"] = "redis"
    app.config["CACHE_REDIS_HOST"] = url.hostname
    app.config["CACHE_REDIS_PORT"] = url.port
    app.config["CACHE_REDIS_PASSWORD"] = url.password
    # from werkzeug.contrib.cache import RedisCache
    # cache = RedisCache(host=url.hostname, port=url.port)
else:
    app.config["CACHE_TYPE"] = "simple"
    # from werkzeug.contrib.cache import SimpleCache
    # cache = SimpleCache()

app.config["CACHE_DEFAULT_TIMEOUT"] = 500
cache = Cache(app)

# STATS = scales.collection('/web',
# meter.MeterStat('hits'),
# scales.IntStat('requests'),
# scales.PmfStat('latency'),
# scales.IntDictStat('byPath'),