main.py (1757B)
1 """Serve the résumé document and its stylesheet.""" 2 3 from datetime import date 4 5 from flask import Flask, render_template, send_from_directory 6 from markupsafe import Markup 7 8 app = Flask(__name__, static_folder=None, template_folder=".") 9 10 11 @app.get("/") 12 def resume(): 13 return render_template("index.html", duration=duration, current_year=date.today().year) 14 15 16 @app.get("/style.css") 17 def stylesheet(): 18 return send_from_directory(app.root_path, "style.css") 19 20 21 @app.get("/robots.txt") 22 def robots(): 23 return send_from_directory(app.root_path, "robots.txt", mimetype="text/plain") 24 25 26 @app.get("/favicon.svg") 27 def favicon(): 28 return send_from_directory(app.root_path, "favicon.svg", mimetype="image/svg+xml") 29 30 31 @app.get("/sitemap.xml") 32 def sitemap(): 33 return send_from_directory(app.root_path, "sitemap.xml", mimetype="application/xml") 34 35 36 def duration(start, end=None): 37 start = date.fromisoformat(f"{start}-01") 38 finish = date.fromisoformat(f"{end}-01") if end else date.today() 39 40 months = (finish.year - start.year) * 12 + finish.month - start.month + 1 41 years, months = divmod(months, 12) 42 43 parts = [ 44 f"{years} year{'s' if years != 1 else ''}" if years else "", 45 f"{months} month{'s' if months != 1 else ''}" if months else "", 46 ] 47 length = ", ".join(filter(None, parts)) 48 49 if end is None: 50 return Markup(f'<time datetime="{start:%Y-%m}">{start.strftime("%B")} {start.year}</time> – Present · {length}') 51 52 return Markup(f'<time datetime="{start:%Y-%m}">{start.strftime("%B")} {start.year}</time> – <time datetime="{finish:%Y-%m}">{finish.strftime("%B")} {finish.year}</time> · {length}') 53 54 55 if __name__ == "__main__": 56 from waitress import serve 57 58 serve(app, host="0.0.0.0", port=8000)