-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
102 lines (89 loc) · 3.96 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
102
from urllib.request import urlopen
import yaml
from flask import Flask, render_template, request
app = Flask(__name__, template_folder='static')
with open("conf.yml", "r") as global_conf_file:
global_conf = yaml.load(global_conf_file, Loader=yaml.UnsafeLoader)
@app.errorhandler(Exception)
def basic_error(e):
return render_template('error.html',
error=e,
url=request.url,
conf=global_conf,
color_bg=global_conf['colors']['background'],
color_fg=global_conf['colors']['foreground'],
color_h=global_conf['colors']['heading'],
color_err=global_conf['colors']['text'])
@app.route("/robots.txt")
def robots():
return "User-Agent: * Disallow: /"
@app.route("/")
def git():
with open("frontpage.yml", "r") as file:
conf = yaml.load(file, Loader=yaml.FullLoader)
print(conf)
username = conf.get("name", {})
return render_template(
'index.html',
color_bg=conf.get("colors",
{}).get("background",
global_conf['colors']['background']),
color_fg=conf.get("colors",
{}).get("foreground",
global_conf['colors']['foreground']),
color_name=conf.get("colors",
{}).get("name", global_conf['colors']['heading']),
color_info=conf.get("colors", {}).get("info",
global_conf['colors']['text']),
color_url=conf.get("colors", {}).get("url", {}).get(
"normal", global_conf['colors']['url']['normal']),
color_url_hover=conf.get("colors", {}).get("url", {}).get(
"hover", global_conf['colors']['url']['hover']),
title=conf.get(
"title", global_conf['title'].replace("{username}",
f"{username}")),
icon=conf.get("icon", global_conf['icon']),
name=conf['name'],
age=conf.get("age", ""),
pronouns=", ".join(conf['pronouns']),
contacts=conf['contacts'],
urls=conf['urls'])
@app.route("/<username>")
def root(username):
with urlopen(f"{global_conf['user-url']}".replace("{username}",
f"{username}")) as data:
yml = data.read().decode('utf-8')
conf = yaml.load(yml, Loader=yaml.FullLoader)
print(conf)
if conf['colors']['background'].startswith("http"):
bg = "url(" + conf['colors'][
'background'] + ") center center/cover no-repeat"
else:
bg = conf['colors']['background']
return render_template(
'index.html',
color_bg=bg,
color_fg=conf.get("colors",
{}).get("foreground",
global_conf['colors']['foreground']),
color_name=conf.get("colors",
{}).get("name", global_conf['colors']['heading']),
color_info=conf.get("colors", {}).get("info",
global_conf['colors']['text']),
color_url=conf.get("colors", {}).get("url", {}).get(
"normal", global_conf['colors']['url']['normal']),
color_url_hover=conf.get("colors", {}).get("url", {}).get(
"hover", global_conf['colors']['url']['hover']),
title=conf.get(
"title", global_conf['title'].replace("{username}",
f"{username}")),
icon=conf.get("icon", global_conf['icon']),
name=conf['name'],
age=conf.get("age", ""),
pronouns=", ".join(conf['pronouns']),
contacts=conf['contacts'],
urls=(lambda x:
[f"https://{i}" if not i.startswith("http") else i
for i in x])(conf['urls']))
if __name__ == "__main__":
app.run(threaded=True)