aboutsummaryrefslogtreecommitdiff
path: root/app.py
blob: 140e31b897836ee06290f913910db3b649ab91bf (plain)
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
from flask import Flask, make_response, render_template, request
from jinja2 import select_autoescape

import repos

app = Flask(__name__)
app.jinja_options['autoescape'] = select_autoescape(default=True)

@app.route('/')
def index():
    return render_template('index.html.jinja')


@app.route('/badge/<package>.svg')
def badge(package: str):
    args = request.args
    versions = repos.get_versions(package, args)
    newest_version = max(versions.values())
    rendered = render_template('badge.svg.jinja', versions=versions, newest_version=newest_version)
    response = make_response(rendered)
    response.headers['Content-Type'] = 'image/svg+xml'
    return response


if __name__ == '__main__':
    app.run()