import json import datetime import requests names = { "pack1": "Pack of 5 Pins
Includes 2x Silver highlights", "pack2": "Pack of 5 Pins
Includes 2x Gold highlights", } images = { "pack1": "pins/pack1.jpg", "pack2": "pins/pack2.jpg", } prices = { "pack1": 45, "pack2": 45, } exchange = { 'rate': 0, 'timestamp': 0 } def cart(cert): html = "" for item in cert: quantity = item['quantity'] path = item['name'] if path in names: name = names[path] image = images[path] price = prices[path] else: name = path image = "pins/pack1.jpg" price = 45 hns = usdToHNS(price) html += "
" html += "
" html += "
" html += f"
" html += "
" html += f"" html += "
" html += f"
" html += f"
US${price}
{hns} HNS
" html += "
" html += script(path) html += "
" return html def cart_total(cert): html = "" for item in cert: quantity = item['quantity'] if int(quantity) <= 0: continue path = item['name'] if path in names: name = names[path] image = images[path] price = prices[path] else: name = path image = "tech/image2.jpg" price = 45 hns = usdToHNS(price, True) hns = hns * int(quantity) hns = "{:,}".format(hns) html += f"
{hns} HNS" html += f"

{name}

" html += f"

{quantity} Packs

" html += "
" return html def script(path): html = f""" """ return html def usdToHNS(usd, returnInt=False): global exchange if exchange['timestamp'] < datetime.datetime.now().timestamp() - 3600: response = requests.get('https://api.coingecko.com/api/v3/simple/price?ids=handshake&vs_currencies=usd') exchange['rate'] = response.json()['handshake']['usd'] exchange['timestamp'] = datetime.datetime.now().timestamp() hns = usd / exchange['rate'] hns = int(hns / 5) * 5 if returnInt: return int(hns) hns = "{:,}".format(hns) return hns def total_usd(cert): total = 0 for item in cert: path = item['name'] if path in prices: total += prices[path] * int(item['quantity']) else: total += 45 * int(item['quantity']) return total def total_hns(cert, returnInt=False): total = 0 for item in cert: path = item['name'] if path in prices: total += usdToHNS(prices[path],True) * int(item['quantity']) else: total += usdToHNS(45,True) * int(item['quantity']) if returnInt: return int(total) total ="{:,}".format(total) return total