From 3b7c587e54fc419b1ff387fa890552935c002015 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 8 Nov 2023 14:01:08 +1100 Subject: [PATCH] feat: Update address every hour from NB api --- main.py | 26 ++++++++++++++++++++++++++ requirements.txt | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 06b165a..f7ae3da 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,9 @@ import dotenv import requests import gift import json +import schedule +import time + app = Flask(__name__) dotenv.load_dotenv() @@ -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') \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index d806e62..d0ab8e7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ flask python-dotenv gunicorn requests -pyotp \ No newline at end of file +pyotp +schedule \ No newline at end of file