feat: Add domain buying and gifting
All checks were successful
Build Docker / Build Image (push) Successful in 27s

This commit is contained in:
Nathan Woodburn 2023-11-08 12:32:05 +11:00
parent 33d65bdd20
commit 7172f448d6
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 64 additions and 2 deletions

61
gift.py
View File

@ -1,10 +1,19 @@
import os import os
import dotenv import dotenv
import json import json
import requests
import pyotp
import time
dotenv.load_dotenv() dotenv.load_dotenv()
loaded = False loaded = False
gifts = [] gifts = []
nbcookie = os.getenv('cookie')
cookies = {"namebase-main": nbcookie}
nb_endpoint = "https://www.namebase.io/"
max_price = 4 # Max price to buy a domain at (in HNS)
def gift(name,email,referer, ip): def gift(name,email,referer, ip):
@ -51,4 +60,56 @@ def gift(name,email,referer, ip):
with open(path, 'w') as f: with open(path, 'w') as f:
json.dump(gifts, f) json.dump(gifts, f)
headers = {"Accept": "application/json", "Content-Type": "application/json"}
params = {"recipientEmail": email, "senderName": "Woodburn Faucet",
"note": "Enjoy your free domain! - Woodburn Faucet"}
names = requests.get(nb_endpoint + "/api/user/domains/owned?offset=0&sortKey=acquiredAt&sortDirection=desc&limit=100"
,headers=headers, cookies=cookies)
if names.status_code != 200:
return "Error getting names:<br>" + names.text
names = names.json()
if len(names['domains']) == 0:
domains_market = requests.get(nb_endpoint + "/api/domains/marketplace?offset=0&buyNowOnly=true&sortKey=price&sortDirection=asc&exclude=%2Cnumbers%2Chyphens%2Cunderscores&maxLength=10&offersOnly=false"
,headers=headers, cookies=cookies)
if domains_market.status_code != 200:
return "Error getting names:<br>" + domains_market.text
domains_market = domains_market.json()
if len(domains_market['domains']) == 0:
return "No domains available to gift<br>Check back in a few minutes"
domain = domains_market['domains'][0]['name']
print("Buying: " + domain,flush=True)
price = int(domains_market['domains'][0]['ammount'])
if price > max_price*1000000:
return "Domain price too high<br>Check back in a few minutes"
payload = {
"listingId": domains_market['domains'][0]['id']
}
buy = requests.post(nb_endpoint + "/api/v0/marketplace/"+domain+"/buynow",headers=headers,data=json.dumps(payload), cookies=cookies)
if buy.status_code != 200:
return "Error buying name:<br>" + buy.text
else:
domain = names['domains'][0]['name']
print("Gifting: " + domain,flush=True)
# Add this name to gifts record
gifts[-1]['domain'] = domain
send_name = requests.post(nb_endpoint + "/api/gift/" + domain.strip(),headers=headers,data=json.dumps(params), cookies=cookies)
if send_name.status_code != 200:
return "Error sending gift:<br>" + send_name.text
return True return True

View File

@ -1,4 +1,5 @@
flask flask
python-dotenv python-dotenv
gunicorn gunicorn
requests requests
pyotp

View File

@ -46,7 +46,7 @@ Claim a free Handshake domain">
<div class="col-12 col-lg-10 mx-auto"> <div class="col-12 col-lg-10 mx-auto">
<div class="text-center position-relative" style="display: block;flex-wrap: wrap;justify-content: flex-end;"> <div class="text-center position-relative" style="display: block;flex-wrap: wrap;justify-content: flex-end;">
<h2 style="width: 100%;">Sorry there was an error with your transfer</h2> <h2 style="width: 100%;">Sorry there was an error with your transfer</h2>
<p style="color: rgb(255,0,0);">{{error}}</p> <p style="color: rgb(255,0,0);">{{error | safe}}</p>
<p style="margin-bottom: 75px;">If you need any help with your domain you can ask in the <a href="https://discord.gg/namebase-664247448469897267" target="_blank">Namebase discord server</a>&nbsp;or by emailing my at <a href="mailto:faucet@nathan.woodburn.au">faucet@nathan.woodburn.au</a></p> <p style="margin-bottom: 75px;">If you need any help with your domain you can ask in the <a href="https://discord.gg/namebase-664247448469897267" target="_blank">Namebase discord server</a>&nbsp;or by emailing my at <a href="mailto:faucet@nathan.woodburn.au">faucet@nathan.woodburn.au</a></p>
</div> </div>
</div> </div>