feat: Alert via discord if the nb token expires
All checks were successful
Build Docker / Build Image (push) Successful in 31s
All checks were successful
Build Docker / Build Image (push) Successful in 31s
This commit is contained in:
parent
96afc29328
commit
e60ae30668
14
main.py
14
main.py
@ -174,15 +174,23 @@ def update_address():
|
|||||||
cookies = {"namebase-main": nbcookie}
|
cookies = {"namebase-main": nbcookie}
|
||||||
headers = {"Accept": "application/json", "Content-Type": "application/json"}
|
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)
|
r = requests.post('https://www.namebase.io/api/v0/deposit/address', data=json.dumps(payload), headers=headers, cookies=cookies)
|
||||||
|
if 'address' not in r.json():
|
||||||
|
print("Error: " + r.text,flush=True)
|
||||||
|
# Send alert via discord
|
||||||
|
webhook = os.getenv('webhook')
|
||||||
|
if webhook != None:
|
||||||
|
payload = {
|
||||||
|
"content": "Error: " + r.text
|
||||||
|
}
|
||||||
|
r = requests.post(webhook, data=json.dumps(payload), headers=headers)
|
||||||
|
return
|
||||||
|
|
||||||
address = r.json()['address']
|
address = r.json()['address']
|
||||||
print("Address updated: " + address,flush=True)
|
print("Address updated: " + address,flush=True)
|
||||||
|
|
||||||
|
|
||||||
update_address()
|
update_address()
|
||||||
|
|
||||||
# Schedule address update every hour
|
|
||||||
schedule.every(1).hour.do(update_address)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -6,3 +6,4 @@ pyotp
|
|||||||
schedule
|
schedule
|
||||||
email-validator
|
email-validator
|
||||||
py3dns
|
py3dns
|
||||||
|
apscheduler
|
@ -7,6 +7,7 @@ import os
|
|||||||
import dotenv
|
import dotenv
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
|
|
||||||
|
|
||||||
class GunicornApp(BaseApplication):
|
class GunicornApp(BaseApplication):
|
||||||
@ -24,6 +25,12 @@ class GunicornApp(BaseApplication):
|
|||||||
return self.application
|
return self.application
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
# Every hour
|
||||||
|
scheduler = BackgroundScheduler()
|
||||||
|
scheduler.add_job(main.update_address, 'cron', hour='*')
|
||||||
|
scheduler.start()
|
||||||
|
|
||||||
|
|
||||||
workers = os.getenv('WORKERS')
|
workers = os.getenv('WORKERS')
|
||||||
threads = os.getenv('THREADS')
|
threads = os.getenv('THREADS')
|
||||||
if workers is None:
|
if workers is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user