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

This commit is contained in:
Nathan Woodburn 2023-11-08 12:55:10 +11:00
parent 29a0a128fb
commit 45b56dc3cb
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 16 additions and 6 deletions

10
gift.py
View File

@ -117,3 +117,13 @@ def gift(name,email,referer, ip):
return True
def balance():
headers = {"Accept": "application/json", "Content-Type": "application/json"}
user_info = requests.get(nb_endpoint + "/api/user",headers=headers, cookies=cookies)
if user_info.status_code != 200:
return "Error getting user info:<br>" + user_info.text
user_info = user_info.json()
hns_balance = user_info['hns_balance']
hns_balance = int(hns_balance)/1000000
return hns_balance

10
main.py
View File

@ -76,11 +76,11 @@ def stats():
# Loop through gifts
referals = {}
for gift in gifts:
if gift['referer'] not in referals:
referals[gift['referer']] = 1
for gift_item in gifts:
if gift_item['referer'] not in referals:
referals[gift_item['referer']] = 1
else:
referals[gift['referer']] += 1
referals[gift_item['referer']] += 1
statsHTML = 'Total gifts: ' + str(len(gifts)) + '<br><br>'
statsHTML += 'Referals:<br>'
@ -88,7 +88,7 @@ def stats():
statsHTML += referal + ': ' + str(referals[referal]) + '<br>'
statsHTML += '<br>Remaining HNS: ' + str(gift.balance()) + '<br>'
return render_template('stats.html',address=address,stats=statsHTML)