feat: Update city page
All checks were successful
Build Docker / Build Main Image (push) Successful in 20s
Build Docker / Build SLDs Image (push) Successful in 20s

This commit is contained in:
Nathan Woodburn 2023-11-15 18:03:43 +11:00
parent 771debdc50
commit 400505d472
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
12 changed files with 163 additions and 14 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@
__pycache__/ __pycache__/
*.json *.json
sites/templates/

View File

@ -34,6 +34,35 @@ def get_website_data(domain):
return parsed return parsed
def get_website_data_raw(domain):
connection = mysql.connector.connect(**dbargs)
cursor = connection.cursor()
cursor.execute("""
SELECT * FROM site WHERE domain = %s
""", (domain,))
data = cursor.fetchall()
cursor.close()
connection.close()
if data == []:
# Create new entry
connection = mysql.connector.connect(**dbargs)
cursor = connection.cursor()
data = {
"data": ""
}
insert_query = "INSERT INTO site (data,domain) VALUES (%s,%s)"
cursor.execute(insert_query, (json.dumps(data), domain))
connection.commit()
cursor.close()
connection.close()
return ""
parsed = data[0][2]
parsed = json.loads(parsed)
return parsed
def get_website_wallet(domain,token): def get_website_wallet(domain,token):
connection = mysql.connector.connect(**dbargs) connection = mysql.connector.connect(**dbargs)
cursor = connection.cursor() cursor = connection.cursor()

View File

@ -30,8 +30,9 @@ def index():
# Get website data # Get website data
data = db.get_website_data(host) data = db.get_website_data(host)
db_object = db.get_website_data_raw(host)
# Render as HTML # Render as HTML
return website.render(data) return website.render(data,db_object)
@app.route('/.well-known/wallets/<token>') @app.route('/.well-known/wallets/<token>')
@ -53,6 +54,18 @@ def catch_all(path):
def not_found(e): def not_found(e):
return redirect('/') return redirect('/')
def clean_template():
# Clean template
with open('templates/city.html') as f:
data = f.read()
data = data.replace('#f1ffff', '{{bg_colour}}')
data = data.replace('#1fffff', '{{text_colour}}')
data = data.replace('#000000', '{{text_colour}}')
# Save
with open('templates/city.html', 'w') as f:
f.write(data)
print("Cleaned template", flush=True)
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=False, port=5000, host='0.0.0.0') app.run(debug=False, port=5000, host='0.0.0.0')

View File

@ -24,6 +24,8 @@ class GunicornApp(BaseApplication):
return self.application return self.application
if __name__ == '__main__': if __name__ == '__main__':
print("Cleaning template...", flush=True)
slds.clean_template()
workers = os.getenv('WORKERS') workers = os.getenv('WORKERS')
threads = os.getenv('THREADS') threads = os.getenv('THREADS')
if workers is None: if workers is None:

View File

@ -7,18 +7,86 @@ main_domain = "cities.hnshosting.au"
if os.getenv('MAIN_DOMAIN') != None: if os.getenv('MAIN_DOMAIN') != None:
main_domain = os.getenv('MAIN_DOMAIN') main_domain = os.getenv('MAIN_DOMAIN')
def render(data): def render(data,db_object):
if data == "": if data == "":
return redirect("https://" + main_domain + '/claim?domain=' + request.host.split('.')[0]) return redirect("https://" + main_domain + '/claim?domain=' + request.host.split('.')[0])
# Render as HTML
html = ""
try: try:
soup = BeautifulSoup(data, 'html.parser') soup = BeautifulSoup(data, 'html.parser')
for script in soup.find_all('script'): for script in soup.find_all('script'):
script.extract() script.extract()
modified = str(soup) html = str(soup)
return render_template_string(modified)
except Exception as e: except Exception as e:
return "<h1>Invalid HTML</h1><br>" + str(e) return "<h1>Invalid HTML</h1><br>" + str(e)
bg_colour = db_object['bg_colour']
hex_colour = bg_colour.lstrip('#')
text_colour = generate_foreground_color(tuple(int(hex_colour[i:i+2], 16) for i in (0, 2, 4)))
text_colour = rgb_to_hex(text_colour)
if (text_colour == "#000000"):
hns_icon = "assets/img/HNS.png"
else:
hns_icon = "assets/img/HNSW.png"
try:
avatar = db_object['avatar']
hnschat = db_object['hnschat']
location = db_object['location']
hns = db_object['HNS']
btc = db_object['BTC']
eth = db_object['ETH']
except Exception as e:
return "<h1>Invalid data</h1><br><h2>Please contact support</h2><br>" + str(e)
return render_template('city.html',html=html,bg_colour=bg_colour,text_colour=text_colour,
avatar=avatar,main_domain=main_domain,
hnschat=hnschat,location=location, hns_icon=hns_icon,
hns=hns,btc=btc,eth=eth, data=html)
def calculate_contrast_ratio(color1, color2):
def calculate_luminance(color):
def adjust_color_value(value):
value /= 255.0
if value <= 0.03928:
return value / 12.92
return ((value + 0.055) / 1.055) ** 2.4
r, g, b = color
r = adjust_color_value(r)
g = adjust_color_value(g)
b = adjust_color_value(b)
return 0.2126 * r + 0.7152 * g + 0.0722 * b
luminance1 = calculate_luminance(color1)
luminance2 = calculate_luminance(color2)
brighter = max(luminance1, luminance2)
darker = min(luminance1, luminance2)
contrast_ratio = (brighter + 0.05) / (darker + 0.05)
return contrast_ratio
def generate_foreground_color(background_color):
# A color with a high contrast ratio against the background color
contrast_color = (255, 255, 255) # White
# Calculate the contrast ratio
ratio = calculate_contrast_ratio(background_color, contrast_color)
# Adjust the contrast color based on the contrast ratio
if ratio < 4.5:
# If the contrast ratio is below the threshold, use black as the foreground color
return (0, 0, 0) # Black
else:
return contrast_color
def rgb_to_hex(rgb_color):
return "#{:02x}{:02x}{:02x}".format(*rgb_color)

View File

@ -4,7 +4,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>shakecities</title> <title>ShakeCities</title>
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">

View File

@ -1 +1 @@
.bs-icon{--bs-icon-size:.75rem;display:flex;flex-shrink:0;justify-content:center;align-items:center;font-size:var(--bs-icon-size);width:calc(var(--bs-icon-size) * 2);height:calc(var(--bs-icon-size) * 2);color:var(--bs-primary)}.bs-icon-xs{--bs-icon-size:1rem;width:calc(var(--bs-icon-size) * 1.5);height:calc(var(--bs-icon-size) * 1.5)}.bs-icon-sm{--bs-icon-size:1rem}.bs-icon-md{--bs-icon-size:1.5rem}.bs-icon-lg{--bs-icon-size:2rem}.bs-icon-xl{--bs-icon-size:2.5rem}.bs-icon.bs-icon-primary{color:var(--bs-white);background:var(--bs-primary)}.bs-icon.bs-icon-primary-light{color:var(--bs-primary);background:rgba(var(--bs-primary-rgb),.2)}.bs-icon.bs-icon-semi-white{color:var(--bs-primary);background:rgba(255,255,255,.5)}.bs-icon.bs-icon-rounded{border-radius:.5rem}.bs-icon.bs-icon-circle{border-radius:50%}.right-align{right:5%} .bs-icon{--bs-icon-size:.75rem;display:flex;flex-shrink:0;justify-content:center;align-items:center;font-size:var(--bs-icon-size);width:calc(var(--bs-icon-size) * 2);height:calc(var(--bs-icon-size) * 2);color:var(--bs-primary)}.bs-icon-xs{--bs-icon-size:1rem;width:calc(var(--bs-icon-size) * 1.5);height:calc(var(--bs-icon-size) * 1.5)}.bs-icon-sm{--bs-icon-size:1rem}.bs-icon-md{--bs-icon-size:1.5rem}.bs-icon-lg{--bs-icon-size:2rem}.bs-icon-xl{--bs-icon-size:2.5rem}.bs-icon.bs-icon-primary{color:var(--bs-white);background:var(--bs-primary)}.bs-icon.bs-icon-primary-light{color:var(--bs-primary);background:rgba(var(--bs-primary-rgb),.2)}.bs-icon.bs-icon-semi-white{color:var(--bs-primary);background:rgba(255,255,255,.5)}.bs-icon.bs-icon-rounded{border-radius:.5rem}.bs-icon.bs-icon-circle{border-radius:50%}.right-align{right:1%}.top-align{top:0;margin-top:1%}.sticky-bottom{width:100%;bottom:1%;left:0}

View File

@ -1,10 +1,10 @@
<!DOCTYPE html> <!DOCTYPE html>
<html data-bs-theme="light" lang="en"> <html data-bs-theme="light" lang="en" style="width: 100vw;height: 99vh;">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>shakecities</title> <title>ShakeCities</title>
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">
@ -16,7 +16,42 @@
<link rel="stylesheet" href="assets/css/styles.min.css"> <link rel="stylesheet" href="assets/css/styles.min.css">
</head> </head>
<body> <body style="height: 99vh;width: 100vw;color: #1fffff;background: #000000;overflow-x: hidden;">
<div>
<div class="d-xl-flex align-items-xl-center" style="background: #f1ffff;border-radius: 10px;padding-top: 2%;padding-left: 2%;padding-right: 2%;padding-bottom: 2%;width: 40%;display: inline-flex;height: 15em;margin-top: 1%;margin-left: 1%;">
<div style="width: 20vw;height: 20vw;max-width: 200px;max-height: 200px;display: inline-block;"><img src="{{avatar}}" width="100%" height="100%" style="border-radius: 50%;"></div>
<div style="display: inline-block;margin-left: 40px;">
<div>
<p style="font-size: 24px;">{{hnschat}}</p>
</div>
<div>
<p style="font-size: 24px;">{{location}}</p>
</div>
</div>
</div>
<div class="d-xl-flex align-items-xl-center right-align top-align" style="background: #f1ffff;border-radius: 10px;padding-top: 2%;padding-left: 2%;padding-bottom: 2%;width: 40%;position: absolute;padding-right: 2%;display: inline-flex;height: 15em;">
<div style="display: inline-block;">
<div>
<p style="font-size: 24px;">HNS: {{hns}}</p>
</div>
<div>
<p style="font-size: 24px;">BTC: {{btc}}</p>
</div>
<div>
<p style="font-size: 24px;">ETH: {{eth}}</p>
</div>
</div>
</div>
</div>
<div style="width: 98%;margin: auto;background: #f1ffff;border-radius: 10px;padding-top: 2%;padding-left: 2%;padding-right: 2%;padding-bottom: 2%;margin-top: 1%;margin-bottom: 1%;">
<p style="font-size: 24px;">{{data|safe}}</p>
</div>
<div class="d-flex justify-content-xl-start align-items-xl-center" style="margin-right: 1%;margin-left: 1%;height: 6%;margin-top: 0.5%;">
<div class="d-inline-block d-print-inline-block d-sm-none d-md-none d-lg-none d-xl-inline-block d-xxl-inline-block" style="display: inline-flex;width: 3vw;height: 3vw;background: #f1ffff;padding: 4px;border-radius: 50%;"><img src="{{hns_icon}}" width="100%" height="100%"></div>
<div class="d-xl-flex align-items-xl-center" style="display: inline-flex;padding: 1%;height: 100%;margin-left: 2%;">
<p class="align-self-baseline" style="color: #f1ffff;">Powered by <a href="https://{{main_domain}}" target="_blank">ShakeCities</a></p>
</div>
</div>
<script src="assets/bootstrap/js/bootstrap.min.js"></script> <script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/script.min.js"></script> <script src="assets/js/script.min.js"></script>
</body> </body>

View File

@ -4,7 +4,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>shakecities</title> <title>ShakeCities</title>
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">

View File

@ -4,7 +4,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>shakecities</title> <title>ShakeCities</title>
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">

View File

@ -4,7 +4,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>shakecities</title> <title>ShakeCities</title>
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">

View File

@ -4,7 +4,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>shakecities</title> <title>ShakeCities</title>
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNSW.png" media="(prefers-color-scheme: dark)">
<link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png"> <link rel="icon" type="image/png" sizes="670x700" href="assets/img/HNS.png">