From 20638a1c093ff875ab09e44cb4bfec5e285f21de Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 3 Nov 2023 14:49:45 +1100 Subject: [PATCH] feat: Add sales count --- .gitignore | 2 ++ requirements.txt | 3 ++- server.py | 17 +++++++++++++++-- templates/index.html | 4 +++- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..963a057 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.env diff --git a/requirements.txt b/requirements.txt index 5a4a2b9..e8fc205 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ flask -python-dotenv \ No newline at end of file +python-dotenv +requests \ No newline at end of file diff --git a/server.py b/server.py index 1db4f08..446c578 100644 --- a/server.py +++ b/server.py @@ -1,6 +1,7 @@ from flask import Flask, make_response, redirect, request, jsonify, render_template, send_from_directory import os import dotenv +import requests app = Flask(__name__) dotenv.load_dotenv() @@ -19,10 +20,22 @@ def index(): tld = host.split('.')[-1] tld = tld.split(':')[0] if tld == 'localhost' or tld == '1': - tld = 'example' + tld = 'freeconcept' https_redirect = "" - return render_template('index.html', tld=tld, https_redirect=https_redirect) + # Count sales + sales = requests.get('https://reg.woodburn.au/api?action=getMyStaked', headers={'Authorization': 'Bearer ' + os.getenv('reg_auth')}) + sales = sales.json() + if 'data' not in sales: + return render_template('index.html', tld=tld, https_redirect=https_redirect, sales=0) + + tld_sales = 0 + sales = sales['data'] + for sale in sales: + if sale['tld'] == tld: + print(sale) + tld_sales = sale['slds'] + return render_template('index.html', tld=tld, https_redirect=https_redirect, sales=tld_sales) # 404 catch all @app.errorhandler(404) diff --git a/templates/index.html b/templates/index.html index 404f1dd..5cb8fd9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -36,7 +36,9 @@
-

.{{tld}}/ domains now available for registration at Woodburn Registry.

Get yourname.{{tld}}/ +

.{{tld}}/ domains now available for registration at Woodburn Registry.

+ Get yourname.{{tld}}/ +

{{sales}} .{{tld}}/ domains claimed so far