SatSale

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 5b62afbc6a3982f15e916bacd7be15e608553bab
parent f76d24e5396cffd1c5dec0ba668b31d37c2378af
Author: Nick <nicholas.w.farrow@gmail.com>
Date:   Thu, 30 Dec 2021 22:48:37 +1100

Add paynym option for donation page - fetches paynym avatar and qr (#33)


Diffstat:
Mconfig.py | 1+
Mconfig.toml | 3+++
Agateways/paynym.py | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msatsale.py | 4++++
4 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/config.py b/config.py @@ -43,4 +43,5 @@ currency_provider = get_opt("currency_provider", "COINGECKO") lightning_address = get_opt("lightning_address", None) lightning_address_comment = get_opt("lightning_address_comment", None) liquid_address = get_opt("liquid_address", None) +paynym = get_opt("paynym", None) free_mode = get_opt("free_mode", False) diff --git a/config.toml b/config.toml @@ -82,6 +82,9 @@ currency_provider = "COINGECKO" # Supported: COINDESK | COINGECKO # This is NOT a trustless swap. Exchange is carried out using sideshift.ai, you bear all associated exchange risks. #liquid_address = None +# Paynym - Display your paynym on your SatSale donation page +#paynym = "+royalcell593" + # DO NOT CHANGE THIS TO TRUE UNLESS YOU WANT ALL PAYMENTS TO AUTOMATICALLY # BE CONSIDERED AS PAID. free_mode = false diff --git a/gateways/paynym.py b/gateways/paynym.py @@ -0,0 +1,98 @@ +import requests + +paynym_site = "https://paynym.is/" + + +def get_paynym(nym): + if nym is None: + return None + + r = requests.get(paynym_site + nym) + + if r.status_code == 200: + nym_html = r.text + nym_html = nym_html.split('<span class="paycode">')[1].split("</span>")[0] + return nym_html + + +def insert_paynym_html(nym): + donate_file = "templates/donate.html" + with open(donate_file, "r") as f: + donate_html = f.read() + + if 'class="paynym"' in donate_html: + print("Found existing paynym HTML in donate.html.") + return + + payment_code = get_paynym(nym) + avatar_url = paynym_site + "{}/avatar".format(payment_code) + codeimage_url = paynym_site + "{}/codeimage".format(payment_code) + + print("Fetching paynym images...") + + avatar_data = requests.get(avatar_url).content + with open("static/avatar.png", "wb") as f: + f.write(avatar_data) + + codeimage_data = requests.get(codeimage_url).content + with open("static/codeimage.png", "wb") as f: + f.write(codeimage_data) + + css_html = """ + <style> + .paynym { + position: relative; + float: left; + } + + .paynym .hoverImg { + position: absolute; + left: 0; + top: 0; + display: none; + } + + .paynym:hover .hoverImg { + display: block; + } + </style> + """ + + paynym_name_html = """ + <small style="vertical-align:middle"><a href="{}" target="_blank">{}</a></small> + """.format( + paynym_site + nym, nym + ) + + nym_html = ( + """ + <div class="paynym"> + <div class="imageInn"> + <img width="100px" style="border-radius:50px;" src="{{ url_for('static', filename='avatar.png') }}"> + </div> + <div class="hoverImg"> + <img width="100px" src="{{ url_for('static', filename='codeimage.png') }}"> + </div> + """ + + """ + <small style="vertical-align:middle"><a href="{}" target="_blank">{}</a></small> + """.format( + paynym_site + nym, nym + ) + + """ + </div> + <br> + """ + ) + + modified_html = donate_html.replace("</head>", css_html + "\n</head>") + modified_html = modified_html.replace( + '<div id="paymentForm">', nym_html + '\n\t<div id="paymentForm">' + ) + + with open(donate_file, "w") as f: + f.write(modified_html) + + print("Wrote donate.html with paynym tags") + + return diff --git a/satsale.py b/satsale.py @@ -16,6 +16,7 @@ from pprint import pprint import json from gateways import ssh_tunnel +from gateways import paynym import config from payments import database, weakhands from payments.price_feed import get_btc_value @@ -320,5 +321,8 @@ if config.lightning_address is not None: from gateways import lightning_address lightning_address.add_ln_address_decorators(app, api, lightning_node) +if config.paynym is not None: + paynym.insert_paynym_html(config.paynym) + if __name__ == "__main__": app.run(debug=False)