-
Notifications
You must be signed in to change notification settings - Fork 5
/
website.py
106 lines (90 loc) · 2.85 KB
/
website.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
102
103
104
105
106
# Flask dependencies
from flask import (
Flask,
render_template,
send_from_directory,
jsonify,
redirect,
request,
session,
make_response,
abort,
)
# Freeze dependencies
from flask_frozen import Freezer
# Project constants
from src import constants
# Misc. dependencies
import requests
import datetime
import time
import os
# Set our Flask config
config = {
"TEMPLATES_AUTO_RELOAD": True, # Auto reload Flask
}
# Define the Flask Application
app = Flask(
__name__, static_url_path="/", static_folder="static", template_folder="templates"
)
app.config.from_mapping(config)
# Define the Freeze instance for SSR
ssr = Freezer(app)
@app.route("/")
def index():
return render_template(
"index.html",
**{
"discord": get_discord_status(),
"me": constants.me,
"social": constants.social_metadata,
"experiences": constants.experiences,
"education": constants.education,
"technologies": constants.technologies,
},
)
@app.route("/r/<name>/")
def social_redirect(name):
if name in constants.social_metadata:
social_data = constants.social_metadata[name]
social_data['title'] = str(name).capitalize()
return render_template(
"redirect.html", **{"social": constants.social_metadata[name]}
)
@app.route("/blog/")
def blog_redirect():
return render_template(
"redirect.html", **{"social": constants.social_metadata['medium']}
)
@app.route("/story/")
def latest_story():
if constants.redirections['story']:
return render_template(
"redirect.html", **{
"social": {
"author": "Eray C. - Medium",
"title": "Biraz konuşalım... #1 - Nisan 2021",
"desc": "Günlük tutmak yerine aylık tutsak nasıl olur? Hayatımdan anlar, yazılara döküp, anlatmak istediğim konuların toplandığı bir alan oluşturmak…",
"color": "#c4c4c4",
"url": constants.redirections['story']
}
}
)
def get_discord_status():
r = requests.get(f"https://api.lanyard.rest/v1/users/{constants.discord_id}")
i = r.json()
try:
return {
"success": True,
"listening": True if i["data"]["listening_to_spotify"] else False,
"avatar": f"https://cdn.discordapp.com/avatars/{constants.discord_id}/{i['data']['discord_user']['avatar']}.gif",
}
except Exception:
return {"success": False, "listening": False}
@app.context_processor
def checkers():
def main_metadata(value):
return constants.main_metadata[value]
def social_metadata(name, value):
return constants.social_metadata[name][value]
return dict(main_metadata=main_metadata, social_metadata=social_metadata)