Compare commits

...

2 Commits

Author SHA1 Message Date
3b7c587e54
feat: Update address every hour from NB api
All checks were successful
Build Docker / Build Image (push) Successful in 29s
2023-11-08 14:01:08 +11:00
aa2e5a1c4d
fix: Cleared up stats balance 2023-11-08 13:35:21 +11:00
2 changed files with 29 additions and 2 deletions

28
main.py
View File

@ -4,6 +4,9 @@ import dotenv
import requests
import gift
import json
import schedule
import time
app = Flask(__name__)
dotenv.load_dotenv()
@ -97,7 +100,7 @@ def stats():
statsHTML += referal + ': ' + str(referals[referal]) + '<br>'
statsHTML += '<br>Remaining HNS: ' + str(gift.balance()) + '<br>'
statsHTML += '<br>Remaining balance: ' + str(gift.balance()) + ' HNS<br>'
return render_template('stats.html',address=address,stats=statsHTML)
@ -117,5 +120,28 @@ def catch_all(path):
def not_found(e):
return redirect('/')
def update_address():
global address
payload = {
"asset": "HNS",
# "timestamp": 1699411892673,
"timestamp": int(round(time.time() * 1000)),
"receiveWindow": 10000
}
nbcookie = os.getenv('cookie')
cookies = {"namebase-main": nbcookie}
headers = {"Accept": "application/json", "Content-Type": "application/json"}
r = requests.post('https://www.namebase.io/api/v0/deposit/address', data=json.dumps(payload), headers=headers, cookies=cookies)
address = r.json()['address']
print("Address updated: " + address,flush=True)
update_address()
# Schedule address update every hour
schedule.every(1).hour.do(update_address)
if __name__ == '__main__':
app.run(debug=False, port=5000, host='0.0.0.0')

View File

@ -3,3 +3,4 @@ python-dotenv
gunicorn
requests
pyotp
schedule