-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
101 lines (77 loc) · 2.52 KB
/
app.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import jinja2
from flask import Flask, render_template, Response, jsonify, url_for, make_response
import json
import sass
import os
import glob
import logging
os.environ['LC_ALL'] = 'en_US.utf-8'
logger = logging.getLogger(__name__)
try:
from flask_weasyprint import HTML, render_pdf
PDF_SUPPORT = True
logging.info("* PDF support enabled")
except (ImportError, OSError):
PDF_SUPPORT = False
logging.info("* PDF support disabled")
app = Flask(__name__, template_folder="templates")
if files := glob.glob("*.resume.json"):
RESUME = files[0]
else:
assert False, "Cannot load resume.json"
if files := glob.glob("resume.pdf"):
RESUME_PDF = files[0]
else:
assert False, "Cannot load resume.pdf"
@app.route("/")
def cv():
with open(RESUME, encoding="utf-8") as o:
document = json.load(o)
return render_template("cv.html", resume=document, print=False)
#
# @app.route("/resume/")
# def resume():
# with open(RESUME, encoding="utf-8") as o:
# document = json.load(o)
# return render_template("resume.html", resume=document, print=False)
@app.route("/print-cv.html")
def print_cv():
with open(RESUME, encoding="utf-8") as o:
document = json.load(o)
return render_template("cv.html", resume=document, print=True)
#
# @app.route("/print-resume.html")
# def print_resume():
# with open(RESUME, encoding="utf-8") as o:
# document = json.load(o)
# return render_template("resume.html", resume=document, print=True)
@app.route("/resume.json")
def resume_json():
with open(RESUME, encoding="utf-8") as o:
return jsonify(json.load(o))
@app.route("/style.css")
def style():
with open("templates/sass/style.sass") as r:
css = sass.compile(string=r.read(), indented=True)
return Response(css, mimetype="text/css")
# PDF Support
if PDF_SUPPORT:
@app.route('/cv.pdf')
def cv_pdf():
return render_pdf(url_for('print_cv'))
@app.route('/resume.pdf')
def resume_pdf():
with open(RESUME_PDF, "rb") as resume_pdf:
binary_pdf = resume_pdf.read()
response = make_response(binary_pdf)
response.headers['Content-Type'] = 'application/pdf'
response.headers['Content-Disposition'] = 'inline; filename=yourfilename.pdf'
return response
# For GitHub Pages
with open(RESUME, encoding="utf-8") as o:
document = json.load(o)
gh_pages = document.get('meta', {}).get('gh-pages-domain') or None
if gh_pages:
@app.route("/CNAME")
def cname():
return Response(gh_pages, mimetype="application/octet-stream")