blob: 030fa94c29301caf247f2336e4c8b9ae55cbfe57 (
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
|
from flask import Flask, make_response, render_template
from jinja2 import select_autoescape
import repos
app = Flask(__name__)
app.jinja_options['autoescape'] = select_autoescape(default=True)
@app.route('/')
def hello_world():
return '<a href="/badge/rust.svg">sample badge for Rust</a>'
@app.route('/badge/<package>.svg')
def badge(package: str):
versions = repos.get_versions(package)
newest_version = max(v for family in versions.values() for v in family.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()
|