thiswebshoprules

git clone https://git.tarina.org/thiswebshoprules
Log | Files | Refs

commit cbf112d815032db1b4be7eb393712ad1fc429f6e
parent ea6054fb64483271ca80e1eb2f8865c76446ae61
Author: rob <rob@tarina.org>
Date:   Sat, 16 Mar 2024 00:33:10 +0200

save btc rate to database

Diffstat:
Mpublic_html/static/robstyle.css | 5++---
Mpublic_html/static/splash.css | 4++--
Mpublic_html/templates/base.html | 2+-
Mpublic_html/templates/index.html | 4+++-
Mpublic_html/templates/splash.html | 2+-
Mserver.py | 64+++++++++++++++++++++++++++++++++++++++++++++++-----------------
6 files changed, 56 insertions(+), 25 deletions(-)

diff --git a/public_html/static/robstyle.css b/public_html/static/robstyle.css @@ -185,7 +185,7 @@ img { margin: 0px auto; height: auto; - max-width: 500px; + max-width: 400px; text-align: center; } @@ -458,9 +458,8 @@ pre .product { - margin: 10px auto; + margin: 0px auto; scroll-margin-top: 10rem; - width: 80%; padding: 10px; border-radius:5px; background-color:#333; diff --git a/public_html/static/splash.css b/public_html/static/splash.css @@ -206,7 +206,7 @@ img width: 80%; height: auto; text-align: center; - max-width: 500px; + max-width: 400px; } .promotext @@ -215,7 +215,7 @@ img width: 50%; height: auto; text-align: center; - max-width: 400px; + max-width: 300px; } .bild diff --git a/public_html/templates/base.html b/public_html/templates/base.html @@ -3,7 +3,7 @@ $def with (content) <HEAD> <meta charset="utf-8"> <title>Gonzo Pi | a reboot of filmmaking</title> - <link rel="stylesheet" href="/static/robstyle.css?v=127" type="text/css" rel="stylesheet"/> + <link rel="stylesheet" href="/static/robstyle.css?v=139" type="text/css" rel="stylesheet"/> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="cache-control" content="no-cache"> </HEAD> diff --git a/public_html/templates/index.html b/public_html/templates/index.html @@ -1,4 +1,4 @@ -$def with (products,bag,sessionkey,productname,inbag,db,getprice,getrate,category,markdown) +$def with (products,bag,sessionkey,productname,inbag,db,getprice,getrate,category,markdown,getbtcratetime) $ totsats = 0 $ toteuro = 0 $ x = 0 @@ -86,6 +86,8 @@ $for i in products: <img class="logo" src="/static/bitcoin.png"> <br> <h2>$getrate()&euro;/₿</h2> +Bitcoin rate from +<h6>$getbtcratetime()</h6> <small>powered by <a href="https://github.com/ElementsProject/lightning">CLN</a>, <a href="https://dev.tarina.org/p/thiswebshoprules/">thiswebshoprules</a> and <a href="https://webpy.org">web.py </a></small> <br> <br> diff --git a/public_html/templates/splash.html b/public_html/templates/splash.html @@ -3,7 +3,7 @@ $def with (content) <HEAD> <meta charset="utf-8"> <title>Gonzo Pi | a reboot of filmmaking</title> - <link rel="stylesheet" href="/static/splash.css?v=98" type="text/css" rel="stylesheet"/> + <link rel="stylesheet" href="/static/splash.css?v=200" type="text/css" rel="stylesheet"/> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="cache-control" content="no-cache"> </HEAD> diff --git a/server.py b/server.py @@ -196,31 +196,61 @@ def getavailable(productid): return '' return name.available +def getbtcrate(): + btc_to_euro = db.select("btcrate", where="currency='EUR'") + #shippinginfo = db.select('shipping', where="country='" + pendinginfo.country + "'", what='price, days')[0] + try: + if time.time() - btc_to_euro[0].timeadded > 6000: + btcrate = 64485 + b = BtcConverter() + btcrate = int(b.get_latest_price('EUR')) + db.update('btcrate', where='currency="EUR"', rate=btcrate, timeadded=time.time()) + else: + btc_to_euro = db.select("btcrate", where="currency='EUR'") + btcrate = btc_to_euro[0].rate + except: + db.insert('btcrate', currency='EUR', rate=64485, timeadded=time.time()) + return btcrate + +def getbtcratetime(): + btc_to_euro = db.select("btcrate", where="currency='EUR'") + btctime = btc_to_euro[0].timeadded + return datetime.datetime.fromtimestamp(btctime).strftime('%c') + def getprice(productid): p = db.query("SELECT * FROM products WHERE id='"+str(productid)+"';")[0] - b = BtcConverter() + #b = BtcConverter() + btcrate=getbtcrate() if p.currency=='euro': - sat = b.convert_to_btc(p.price/100, 'EUR') * 100000000 + sat = 1/btcrate*(p.price/100) * 100000000 + #sat = b.convert_to_btc(p.price/100, 'EUR') * 100000000 euro = p.price/100 if p.currency=='bitcoin': - euro = b.convert_btc_to_cur(p.price/100000000,'EUR') + euro = btcrate*p.price/100000000 + #euro = b.convert_btc_to_cur(p.price/100000000,'EUR') sat = p.price return int(sat), round(euro,2) def btc_to_eur(amount): - b = BtcConverter() - euro = round(b.convert_btc_to_cur(amount/100000000,'EUR'),2) + #b = BtcConverter() + btcrate=getbtcrate() + #euro = round(b.convert_btc_to_cur(amount/100000000,'EUR'),2) + euro = round(btcrate*amount/100000000) return euro def eur_to_sat(amount): - b = BtcConverter() - btc = b.convert_to_btc(amount/100, 'EUR') + btcrate=getbtcrate() + #b = BtcConverter() + #btc = b.convert_to_btc(amount/100, 'EUR') + btc = 1/btcrate*(amount/100) sat=btc*100000000 return int(sat) def getrate(): - b = BtcConverter() - return int(b.get_latest_price('EUR')) + #b = BtcConverter() + btcrate=getbtcrate() + #return int(b.get_latest_price('EUR')) + return int(btcrate) def checkforoldbags(): print('checking for old bags') @@ -315,7 +345,7 @@ class index(): inbag = None if inbag < 1: session.sessionkey = 'empty' - return render.index(products,bag,session.sessionkey,productname,inbag,db,getprice,getrate,i.category, markdown) + return render.index(products,bag,session.sessionkey,productname,inbag,db,getprice,getrate,i.category, markdown,getbtcratetime) class almost(): def GET(self): @@ -510,13 +540,13 @@ class payln: msg = 'You got a new order, from ' + customer.firstname + ' ' + customer.lastname + ' from ' + customer.country + ' email: ' + customer.email + ' this dude wantz ' + lninvoice['description'] else: msg='sup?' - sendmail(webmaster, 'Tarina Shop', msg) + sendmail(webmaster, 'Gonzo Pi Shop', msg) # send mail to customer if ordertype()=='physical': msg = "Thank you for order " + lninvoice['description'] + " at Tarina shop, we'll be processing your order as soon as possible and send it to " + customer.firstname + ' ' + customer.lastname + ', ' + customer.address + ', ' + str(customer.postalcode) + ', ' + customer.town + ', ' + customer.country + '. To pay/view status or take a look at the digital goodies of your order please visit ' + baseurl + '/goodies/'+digitalkey else: msg='sup? thanks! here the goodies '+baseurl+'/goodies/'+digitalkey - sendmail(customer.email, 'Groove the Fuck Out!', msg) + sendmail(customer.email, 'Gonzo Pi Shop', msg) web.seeother('/payln/'+invoice_key) if lninvoice['status'] == 'paid': bag = db.query("SELECT * FROM paidbags WHERE sessionkey='"+invoice_key+"';") @@ -550,7 +580,7 @@ class paybtc: if invoice.datepaid == None and confirmations > 6: msg = 'Gonzo Pi shop order update! someone sent you Bitcoin! ' + baseurl + '/paybtc/' + invoice.invoice_key print(msg) - sendmail(webmaster, 'Tarina Shop', msg) + sendmail(webmaster, 'Gonzo Pi Shop', msg) db.update('invoices', where="invoice_key='" + invoice.invoice_key + "'", status='paid', datepaid=time.strftime('%Y-%m-%d %H:%M:%S')) pendinginfo = getpendinginfo() bag = db.query("SELECT * FROM customerbag WHERE sessionkey='"+invoice_key+"';") @@ -572,16 +602,16 @@ class orders(): paylink = 'payln/' if i.status == 'thankyou': msg="Hi " + customer.email + ", thank you for your order! You can track the status of your order at "+baseurl+'/'+paylink+i.key - sendmail(customer.email, 'Tarina Shop, a thank you!', msg) + sendmail(customer.email, 'Gonzo Pi Shop, a thank you!', msg) elif i.status == 'shipped': msg="Hi " + customer.email + ", your order has been shipped!. You can track the status of your order at "+baseurl+'/'+paylink+i.key - sendmail(customer.email, 'Tarina Shop, your order has been shipped!', msg) + sendmail(customer.email, 'Gonzo Pi Shop, your order has been shipped!', msg) elif i.status == 'paynotice': msg="Hi " + customer.email + ", we noticed you have an unpaid order in our shop, thank you. You can track the status of your order at " + baseurl + paylink + payment.invoice_key - sendmail(customer.email, 'Tarina Shop, order waiting for payment!', msg) + sendmail(customer.email, 'Gonzo Pi Shop, order waiting for payment!', msg) elif i.status == 'paid': msg="Hi " + customer.email + ", thank you! payment received. You can track the status of your order at " + baseurl + paylink + payment.invoice_key - sendmail(customer.email, 'Tarina Shop, order payment received', msg) + sendmail(customer.email, 'Gonzo Pi Shop, order payment received', msg) raise web.seeother(referer) payments = db.select('invoices', what='btc, ln, invoice_key, products, payment, amount, totsats, timestamp, status, datepaid, dateshipped', order='timestamp DESC') if i.key == None and i.status != None: