resume_page

Log | Files | Refs | README

main.py (1347B)


      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)
     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("/sitemap.xml")
     27 def sitemap():
     28     return send_from_directory(app.root_path, "sitemap.xml", mimetype="application/xml")
     29 
     30 
     31 def duration(start, end=None):
     32     start = date.fromisoformat(f"{start}-01")
     33     finish = date.fromisoformat(f"{end}-01") if end else date.today()
     34 
     35     months = (finish.year - start.year) * 12 + finish.month - start.month + 1
     36     years, months = divmod(months, 12)
     37 
     38     parts = [
     39         f"{years} year{'s' if years != 1 else ''}" if years else "",
     40         f"{months} month{'s' if months != 1 else ''}" if months else "",
     41     ]
     42     length = ", ".join(filter(None, parts))
     43 
     44     return Markup(f'<time datetime="{start:%Y-%m}">{start.year}</time> · {length}')
     45 
     46 
     47 if __name__ == "__main__":
     48     from waitress import serve
     49 
     50     serve(app, host="0.0.0.0", port=8000)