feat: Add stats page
All checks were successful
Build Docker / Build Image (push) Successful in 29s

This commit is contained in:
Nathan Woodburn 2023-11-08 12:48:17 +11:00
parent 7172f448d6
commit 29a0a128fb
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
4 changed files with 148 additions and 8 deletions

View File

@ -12,6 +12,6 @@ COPY . /app
VOLUME /data VOLUME /data
ENTRYPOINT ["python3"] ENTRYPOINT ["python3"]
CMD ["main.py"] CMD ["server.py"]
FROM builder as dev-envs FROM builder as dev-envs

View File

@ -13,7 +13,7 @@ nbcookie = os.getenv('cookie')
cookies = {"namebase-main": nbcookie} cookies = {"namebase-main": nbcookie}
nb_endpoint = "https://www.namebase.io/" nb_endpoint = "https://www.namebase.io/"
max_price = 4 # Max price to buy a domain at (in HNS) max_price = 5 # Max price to buy a domain at (in HNS)
def gift(name,email,referer, ip): def gift(name,email,referer, ip):
@ -104,6 +104,10 @@ def gift(name,email,referer, ip):
# Add this name to gifts record # Add this name to gifts record
gifts[-1]['domain'] = domain gifts[-1]['domain'] = domain
# Save the file
with open(path, 'w') as f:
json.dump(gifts, f)
send_name = requests.post(nb_endpoint + "/api/gift/" + domain.strip(),headers=headers,data=json.dumps(params), cookies=cookies) send_name = requests.post(nb_endpoint + "/api/gift/" + domain.strip(),headers=headers,data=json.dumps(params), cookies=cookies)

43
main.py
View File

@ -3,6 +3,7 @@ import os
import dotenv import dotenv
import requests import requests
import gift import gift
import json
app = Flask(__name__) app = Flask(__name__)
dotenv.load_dotenv() dotenv.load_dotenv()
@ -60,16 +61,46 @@ def send_wallet(token):
address = requests.get('https://nathan.woodburn.au/.well-known/wallets/'+token).text address = requests.get('https://nathan.woodburn.au/.well-known/wallets/'+token).text
return make_response(address, 200, {'Content-Type': 'text/plain'}) return make_response(address, 200, {'Content-Type': 'text/plain'})
@app.route('/stats')
def stats():
# Read the file
path = '/data/gifts.json'
if os.getenv('local') == 'true':
path = './gifts.json'
# Load file
gifts = []
if os.path.isfile(path):
with open(path, 'r') as f:
gifts = json.load(f)
# Loop through gifts
referals = {}
for gift in gifts:
if gift['referer'] not in referals:
referals[gift['referer']] = 1
else:
referals[gift['referer']] += 1
statsHTML = 'Total gifts: ' + str(len(gifts)) + '<br><br>'
statsHTML += 'Referals:<br>'
for referal in referals:
statsHTML += referal + ': ' + str(referals[referal]) + '<br>'
return render_template('stats.html',address=address,stats=statsHTML)
@app.route('/<path:path>') @app.route('/<path:path>')
def catch_all(path): def catch_all(path):
# If file exists, load it # # If file exists, load it
if os.path.isfile('templates/' + path): # if os.path.isfile('templates/' + path):
return render_template(path) # return render_template(path)
# Try with .html # # Try with .html
if os.path.isfile('templates/' + path + '.html'): # if os.path.isfile('templates/' + path + '.html'):
return render_template(path + '.html') # return render_template(path + '.html')
return redirect('/') return redirect('/')
# 404 catch all # 404 catch all

105
templates/stats.html Normal file
View File

@ -0,0 +1,105 @@
<!DOCTYPE html>
<html data-bs-theme="light" lang="en-au">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>Home - Woodburn Faucet</title>
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://faucet.woodburn.au/assets/img/android-chrome-512x512.png">
<meta property="og:description" content="Woodburn Faucet
Claim a free Handshake domain">
<meta name="twitter:title" content="Woodburn Faucet">
<meta property="og:image" content="https://faucet.woodburn.au/assets/img/android-chrome-512x512.png">
<meta property="og:type" content="website">
<meta name="description" content="Woodburn Faucet
Claim a free Handshake domain">
<meta property="og:title" content="Woodburn Faucet">
<meta name="twitter:description" content="Woodburn Faucet
Claim a free Handshake domain">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="assets/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="16x16" href="assets/img/favicon-16x16.png">
<link rel="icon" type="image/png" sizes="16x16" href="assets/img/favicon-16x16.png" media="(prefers-color-scheme: dark)">
<link rel="icon" type="image/png" sizes="32x32" href="assets/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="32x32" href="assets/img/favicon-32x32.png" media="(prefers-color-scheme: dark)">
<link rel="icon" type="image/png" sizes="180x180" href="assets/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="192x192" href="assets/img/android-chrome-192x192.png">
<link rel="icon" type="image/png" sizes="512x512" href="assets/img/android-chrome-512x512.png">
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800&amp;display=swap">
<link rel="stylesheet" href="assets/fonts/material-icons.min.css">
</head>
<body style="background: rgb(39,38,46);">
<nav class="navbar navbar-expand-md sticky-top py-3 navbar-dark" id="mainNav">
<div class="container"><a class="navbar-brand d-flex align-items-center" href="/"><img src="assets/img/favicon.svg" width="50em"><span>&nbsp;Woodburn Faucet</span></a><button class="navbar-toggler" data-bs-toggle="collapse"><span class="visually-hidden">Toggle navigation</span><span class="navbar-toggler-icon"></span></button></div>
</nav>
<header class="bg-dark" style="background: rgb(39, 38, 46);">
<div class="container pt-4 pt-xl-5">
<div class="row pt-5">
<div class="col-md-8 col-xl-6 text-center text-md-start mx-auto" style="margin-bottom: 50px;">
<div class="text-center">
<p class="fw-bold text-success mb-2">Nathan.Woodburn/</p>
<h1 class="fw-bold">Woodburn Faucet Stats</h1>
</div>
</div>
<div class="col-12 col-lg-10 mx-auto">
<div class="text-center position-relative" style="display: block;flex-wrap: wrap;justify-content: flex-end;">
<h2 style="width: 100%;">{{stats | safe}}</h2>
<p style="margin-bottom: 75px;">If you need any help with your domain you can ask in the <a href="https://discord.gg/namebase-664247448469897267" target="_blank">Namebase discord server</a>&nbsp;or by emailing my at <a href="mailto:faucet@nathan.woodburn.au">faucet@nathan.woodburn.au</a></p>
</div>
</div>
</div>
</div>
</header>
<section style="margin-top: 50px;">
<div style="text-align: center;">
<h3>Donate to fund the faucet</h3>
<h4>{{address}}</h4>
</div>
</section>
<section style="background: #27262e;">
<div class="container bg-dark py-5">
<div class="row">
<div class="col-md-8 col-xl-6 text-center mx-auto">
<p class="fw-bold text-success mb-2">Our Services</p>
<h3 class="fw-bold">What we can do for you</h3>
</div>
</div>
<div class="py-5 p-lg-5">
<div class="row row-cols-1 row-cols-md-2 mx-auto" style="max-width: 900px;">
<div class="col mb-5">
<div class="card shadow-sm">
<div class="card-body px-4 py-5 px-md-5">
<div class="bs-icon-lg d-flex justify-content-center align-items-center mb-3 bs-icon" style="top: 1rem;right: 1rem;position: absolute;"><i class="material-icons text-success">web</i></div>
<h5 class="fw-bold card-title">HNS Hosting</h5>
<p class="text-muted card-text mb-4">Providing website hosting for Handshake domains. Wordpress sites or static html sites.</p><a class="btn btn-primary shadow" role="button" target="_blank" href="https://hnshosting.au">Learn more</a>
</div>
</div>
</div>
<div class="col mb-5">
<div class="card shadow-sm">
<div class="card-body px-4 py-5 px-md-5">
<div class="bs-icon-lg d-flex justify-content-center align-items-center mb-3 bs-icon" style="top: 1rem;right: 1rem;position: absolute;"><i class="material-icons text-success">dns</i></div>
<h5 class="fw-bold card-title">Woodburn Registry</h5>
<p class="text-muted card-text mb-4">Free Handshake compatible DNS server. Also provides free SLDs for testing</p><a class="btn btn-primary shadow" role="button" href="https://reg.woodburn.au" target="_blank">Learn more</a>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<footer class="bg-dark">
<div class="container py-4 py-lg-5">
<hr>
<div class="text-muted d-flex justify-content-between align-items-center pt-3">
<p class="mb-0 copyright">Copyright © 2023 Nathan.Woodburn/</p>
</div>
</div>
</footer>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/script.min.js"></script>
</body>
</html>