6cebe6413cba1ca3d3267f60bb3b80f9ad1fb591.html (69700B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 5 <title>first - getdafuckouttahere.net - Unnamed repository; edit this file 'description' to name the repository. 6 </title> 7 <link rel="icon" type="image/png" href="../favicon.png" /> 8 <link rel="alternate" type="application/atom+xml" title="getdafuckouttahere.net Atom Feed" href="../atom.xml" /> 9 <link rel="alternate" type="application/atom+xml" title="getdafuckouttahere.net Atom Feed (tags)" href="../tags.xml" /> 10 <link rel="stylesheet" type="text/css" href="../style.css" /> 11 </head> 12 <body> 13 <table><tr><td><a href="../../"><img src="../logo.png" alt="" width="32" height="32" /></a></td><td><h1>getdafuckouttahere.net</h1><span class="desc">Unnamed repository; edit this file 'description' to name the repository. 14 </span></td></tr><tr><td></td><td> 15 <a href="../log.html">Log</a> | <a href="../files.html">Files</a> | <a href="../refs.html">Refs</a></td></tr></table> 16 <hr/> 17 <div id="content"> 18 <pre><b>commit</b> <a href="../commit/6cebe6413cba1ca3d3267f60bb3b80f9ad1fb591.html">6cebe6413cba1ca3d3267f60bb3b80f9ad1fb591</a> 19 <b>Author:</b> rob <<a href="mailto:rob@tarina.org">rob@tarina.org</a>> 20 <b>Date:</b> Sat, 16 Oct 2021 07:45:16 +0300 21 22 first 23 24 <b>Diffstat:</b> 25 <table><tr><td class="A">A</td><td><a href="#h0">server.py</a></td><td> | </td><td class="num">673</td><td><span class="i">+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</span><span class="d"></span></td></tr> 26 </table></pre><pre>1 file changed, 673 insertions(+), 0 deletions(-) 27 <hr/><b>diff --git a/<a id="h0" href="../file/server.py.html">server.py</a> b/<a href="../file/server.py.html">server.py</a></b> 28 <a href="#h0-0" id="h0-0" class="h">@@ -0,0 +1,673 @@ 29 </a><a href="#h0-0-0" id="h0-0-0" class="i">+#!/usr/bin/python3 30 </a><a href="#h0-0-1" id="h0-0-1" class="i">+# -*- coding: utf-8 -*- 31 </a><a href="#h0-0-2" id="h0-0-2" class="i">+ 32 </a><a href="#h0-0-3" id="h0-0-3" class="i">+import time, datetime, os, sys 33 </a><a href="#h0-0-4" id="h0-0-4" class="i">+ 34 </a><a href="#h0-0-5" id="h0-0-5" class="i">+file_dir = os.path.dirname(__file__) 35 </a><a href="#h0-0-6" id="h0-0-6" class="i">+sys.path.append(file_dir) 36 </a><a href="#h0-0-7" id="h0-0-7" class="i">+ 37 </a><a href="#h0-0-8" id="h0-0-8" class="i">+import json 38 </a><a href="#h0-0-9" id="h0-0-9" class="i">+import requests 39 </a><a href="#h0-0-10" id="h0-0-10" class="i">+import subprocess 40 </a><a href="#h0-0-11" id="h0-0-11" class="i">+import web 41 </a><a href="#h0-0-12" id="h0-0-12" class="i">+import hashlib 42 </a><a href="#h0-0-13" id="h0-0-13" class="i">+import random 43 </a><a href="#h0-0-14" id="h0-0-14" class="i">+import time 44 </a><a href="#h0-0-15" id="h0-0-15" class="i">+import shutil 45 </a><a href="#h0-0-16" id="h0-0-16" class="i">+import settings 46 </a><a href="#h0-0-17" id="h0-0-17" class="i">+from PIL import Image 47 </a><a href="#h0-0-18" id="h0-0-18" class="i">+from forex_python.bitcoin import BtcConverter 48 </a><a href="#h0-0-19" id="h0-0-19" class="i">+from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException 49 </a><a href="#h0-0-20" id="h0-0-20" class="i">+ 50 </a><a href="#h0-0-21" id="h0-0-21" class="i">+urls = ( 51 </a><a href="#h0-0-22" id="h0-0-22" class="i">+ '/?', 'index', 52 </a><a href="#h0-0-23" id="h0-0-23" class="i">+ '/putinbag/(.*)', 'putinbag', 53 </a><a href="#h0-0-24" id="h0-0-24" class="i">+ '/dropitem/(.*)?', 'dropitem', 54 </a><a href="#h0-0-25" id="h0-0-25" class="i">+ '/payln/(.*)', 'payln', 55 </a><a href="#h0-0-26" id="h0-0-26" class="i">+ '/paybtc/(.*)', 'paybtc', 56 </a><a href="#h0-0-27" id="h0-0-27" class="i">+ '/payment/(.*)', 'payment', 57 </a><a href="#h0-0-28" id="h0-0-28" class="i">+ '/checkout/(.*)', 'checkout', 58 </a><a href="#h0-0-29" id="h0-0-29" class="i">+ '/pending/(.*)', 'pending', 59 </a><a href="#h0-0-30" id="h0-0-30" class="i">+ '/thankyou', 'thankyou', 60 </a><a href="#h0-0-31" id="h0-0-31" class="i">+ '/login', 'login', 61 </a><a href="#h0-0-32" id="h0-0-32" class="i">+ '/logout', 'logout', 62 </a><a href="#h0-0-33" id="h0-0-33" class="i">+ '/products/(.*)?', 'products', 63 </a><a href="#h0-0-34" id="h0-0-34" class="i">+ '/bigpic/(.*)?', 'bigpic', 64 </a><a href="#h0-0-35" id="h0-0-35" class="i">+ '/categories?', 'categories', 65 </a><a href="#h0-0-36" id="h0-0-36" class="i">+ '/op', 'op', 66 </a><a href="#h0-0-37" id="h0-0-37" class="i">+ '/bitcoin', 'bitcoin', 67 </a><a href="#h0-0-38" id="h0-0-38" class="i">+ '/shipping/(.*)', 'shipping', 68 </a><a href="#h0-0-39" id="h0-0-39" class="i">+ '/payments?', 'payments') 69 </a><a href="#h0-0-40" id="h0-0-40" class="i">+ 70 </a><a href="#h0-0-41" id="h0-0-41" class="i">+allowed = (("rbckman", "secret"), 71 </a><a href="#h0-0-42" id="h0-0-42" class="i">+ ("brkhelle", "topsecret")) 72 </a><a href="#h0-0-43" id="h0-0-43" class="i">+ 73 </a><a href="#h0-0-44" id="h0-0-44" class="i">+productsbad = (("GetDaFuckOuttaHere", 420.00), 74 </a><a href="#h0-0-45" id="h0-0-45" class="i">+ ("GetDaFuckOuttaHere Viewfinder", 80.00), 75 </a><a href="#h0-0-46" id="h0-0-46" class="i">+ ("Picamera", 30.00), 76 </a><a href="#h0-0-47" id="h0-0-47" class="i">+ ("Donation", 0.005)) 77 </a><a href="#h0-0-48" id="h0-0-48" class="i">+ 78 </a><a href="#h0-0-49" id="h0-0-49" class="i">+bag = '' 79 </a><a href="#h0-0-50" id="h0-0-50" class="i">+ 80 </a><a href="#h0-0-51" id="h0-0-51" class="i">+#Load from settings 81 </a><a href="#h0-0-52" id="h0-0-52" class="i">+ 82 </a><a href="#h0-0-53" id="h0-0-53" class="i">+rpcauth = settings.rpcauth 83 </a><a href="#h0-0-54" id="h0-0-54" class="i">+charge_url = settings.charge_url 84 </a><a href="#h0-0-55" id="h0-0-55" class="i">+webmaster = settings.webmaster 85 </a><a href="#h0-0-56" id="h0-0-56" class="i">+baseurl = settings.baseurl 86 </a><a href="#h0-0-57" id="h0-0-57" class="i">+ 87 </a><a href="#h0-0-58" id="h0-0-58" class="i">+ 88 </a><a href="#h0-0-59" id="h0-0-59" class="i">+basedir = os.path.dirname(os.path.realpath(__file__)) 89 </a><a href="#h0-0-60" id="h0-0-60" class="i">+templatedir = basedir + '/public_html/templates/' 90 </a><a href="#h0-0-61" id="h0-0-61" class="i">+staticdir = basedir + '/public_html/static/' 91 </a><a href="#h0-0-62" id="h0-0-62" class="i">+web.config.debug = False 92 </a><a href="#h0-0-63" id="h0-0-63" class="i">+app = web.application(urls, globals()) 93 </a><a href="#h0-0-64" id="h0-0-64" class="i">+store = web.session.DiskStore(basedir + '/sessions') 94 </a><a href="#h0-0-65" id="h0-0-65" class="i">+render = web.template.render(templatedir, base="base") 95 </a><a href="#h0-0-66" id="h0-0-66" class="i">+renderop = web.template.render(templatedir, base="op") 96 </a><a href="#h0-0-67" id="h0-0-67" class="i">+db = web.database(dbn='sqlite', db=basedir + "/db/cyberpunkcafe.db") 97 </a><a href="#h0-0-68" id="h0-0-68" class="i">+session = web.session.Session(app,store,initializer={'login':0, 'privilege':0, 'bag':[], 'sessionkey':0}) 98 </a><a href="#h0-0-69" id="h0-0-69" class="i">+ 99 </a><a href="#h0-0-70" id="h0-0-70" class="i">+#----------- Database setup ------------- 100 </a><a href="#h0-0-71" id="h0-0-71" class="i">+ 101 </a><a href="#h0-0-72" id="h0-0-72" class="i">+#Remeber to store Euros in cents 102 </a><a href="#h0-0-73" id="h0-0-73" class="i">+ 103 </a><a href="#h0-0-74" id="h0-0-74" class="i">+#CREATE TABLE products (id integer PRIMARY KEY, name text NOT NULL, description text, price integer NOT NULL, available integer, sold integer, priority integer, dateadded integer, datelastsold integer, daterunout integer, dateavailable integer); 104 </a><a href="#h0-0-75" id="h0-0-75" class="i">+ 105 </a><a href="#h0-0-76" id="h0-0-76" class="i">+#CREATE TABLE shipping (id integer PRIMARY KEY, country text NOT NULL, cost integer NOT NULL, days integer NOT NULL); 106 </a><a href="#h0-0-77" id="h0-0-77" class="i">+ 107 </a><a href="#h0-0-78" id="h0-0-78" class="i">+#should rename to customer 108 </a><a href="#h0-0-79" id="h0-0-79" class="i">+#CREATE TABLE pending (id integer PRIMARY KEY, invoice_key text NOT NULL, country text NOT NULL, firstname text NOT NULL, lastname text NOT NULL, address text NOT NULL, town text NOT NULL, postalcode integer NOT NULL, email text NOT NULL, dateadded integer) 109 </a><a href="#h0-0-80" id="h0-0-80" class="i">+ 110 </a><a href="#h0-0-81" id="h0-0-81" class="i">+#CREATE TABLE invoices (id INT AUTO_INCREMENT, invoice_key TEXT, btc TEXT, ln TEXT, products TEXT, payment TEXT, amount INT, totsats INT, timestamp TIMESTAMP, status TEXT, datepaid TIMESTAMP, dateshipped TIMESTAMP); 111 </a><a href="#h0-0-82" id="h0-0-82" class="i">+ 112 </a><a href="#h0-0-83" id="h0-0-83" class="i">+ 113 </a><a href="#h0-0-84" id="h0-0-84" class="i">+def logged(): 114 </a><a href="#h0-0-85" id="h0-0-85" class="i">+ if session.login == 1: 115 </a><a href="#h0-0-86" id="h0-0-86" class="i">+ return True 116 </a><a href="#h0-0-87" id="h0-0-87" class="i">+ else: 117 </a><a href="#h0-0-88" id="h0-0-88" class="i">+ return False 118 </a><a href="#h0-0-89" id="h0-0-89" class="i">+ 119 </a><a href="#h0-0-90" id="h0-0-90" class="i">+def sendmail(email, subject, msg): 120 </a><a href="#h0-0-91" id="h0-0-91" class="i">+ #Send mail 121 </a><a href="#h0-0-92" id="h0-0-92" class="i">+ echomsg = subprocess.Popen(('echo', msg), stdout=subprocess.PIPE) 122 </a><a href="#h0-0-93" id="h0-0-93" class="i">+ sendmsg = subprocess.check_output(('mail', '-r', 'rob@tarina.org', '-s', subject, email), stdin=echomsg.stdout) 123 </a><a href="#h0-0-94" id="h0-0-94" class="i">+ echomsg.wait() 124 </a><a href="#h0-0-95" id="h0-0-95" class="i">+ #subprocess.call(['echo', msg, '|', 'mail', '-r', 'rob@tarina.org','-s', subject, email]) 125 </a><a href="#h0-0-96" id="h0-0-96" class="i">+ 126 </a><a href="#h0-0-97" id="h0-0-97" class="i">+def createinvoice(amount, description, invoice_key): 127 </a><a href="#h0-0-98" id="h0-0-98" class="i">+ #Cents to EUR 128 </a><a href="#h0-0-99" id="h0-0-99" class="i">+ amount = str(amount*1000) 129 </a><a href="#h0-0-100" id="h0-0-100" class="i">+ invoice_details = {"msatoshi":amount, "description": "{}".format(description)} 130 </a><a href="#h0-0-101" id="h0-0-101" class="i">+ print(invoice_details) 131 </a><a href="#h0-0-102" id="h0-0-102" class="i">+ resp = requests.post(charge_url+'/invoice/', json=invoice_details) 132 </a><a href="#h0-0-103" id="h0-0-103" class="i">+ #print(resp.json()) 133 </a><a href="#h0-0-104" id="h0-0-104" class="i">+ return resp.json() 134 </a><a href="#h0-0-105" id="h0-0-105" class="i">+ 135 </a><a href="#h0-0-106" id="h0-0-106" class="i">+def getinvoice(id): 136 </a><a href="#h0-0-107" id="h0-0-107" class="i">+ resp = requests.get(charge_url+'/invoice/'+id) 137 </a><a href="#h0-0-108" id="h0-0-108" class="i">+ print(resp.json()) 138 </a><a href="#h0-0-109" id="h0-0-109" class="i">+ return resp.json() 139 </a><a href="#h0-0-110" id="h0-0-110" class="i">+ 140 </a><a href="#h0-0-111" id="h0-0-111" class="i">+def callsubprocess(cmd): 141 </a><a href="#h0-0-112" id="h0-0-112" class="i">+ subprocess.call(cmd.split()) 142 </a><a href="#h0-0-113" id="h0-0-113" class="i">+ 143 </a><a href="#h0-0-114" id="h0-0-114" class="i">+def dropitems(d): 144 </a><a href="#h0-0-115" id="h0-0-115" class="i">+ i = getproduct(d) 145 </a><a href="#h0-0-116" id="h0-0-116" class="i">+ db.update('products', where="id='"+str(i.id)+"'", available=i.available+1) 146 </a><a href="#h0-0-117" id="h0-0-117" class="i">+ product = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"' AND product='"+str(i.id)+"';")[0] 147 </a><a href="#h0-0-118" id="h0-0-118" class="i">+ if product.quantity > 1: 148 </a><a href="#h0-0-119" id="h0-0-119" class="i">+ db.update('customerbag', where="sessionkey='" + session.sessionkey +"' and product='"+str(i.id)+"'", quantity=product.quantity-1) 149 </a><a href="#h0-0-120" id="h0-0-120" class="i">+ else: 150 </a><a href="#h0-0-121" id="h0-0-121" class="i">+ db.query("DELETE FROM customerbag WHERE sessionkey='" + session.sessionkey +"' AND product='"+str(i.id)+"';") 151 </a><a href="#h0-0-122" id="h0-0-122" class="i">+ 152 </a><a href="#h0-0-123" id="h0-0-123" class="i">+def addtobag(p): 153 </a><a href="#h0-0-124" id="h0-0-124" class="i">+ i = getproduct(p) 154 </a><a href="#h0-0-125" id="h0-0-125" class="i">+ if i.available > 0: 155 </a><a href="#h0-0-126" id="h0-0-126" class="i">+ #session.bag += (i.name, i.price, i.id), 156 </a><a href="#h0-0-127" id="h0-0-127" class="i">+ db.update('products', where="id='"+str(i.id)+"'", available=i.available-1) 157 </a><a href="#h0-0-128" id="h0-0-128" class="i">+ product = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"' AND product='"+str(i.id)+"';") 158 </a><a href="#h0-0-129" id="h0-0-129" class="i">+ if product: 159 </a><a href="#h0-0-130" id="h0-0-130" class="i">+ product = product[0] 160 </a><a href="#h0-0-131" id="h0-0-131" class="i">+ print(product) 161 </a><a href="#h0-0-132" id="h0-0-132" class="i">+ db.update('customerbag', where="sessionkey='" + session.sessionkey +"' and product='"+str(i.id)+"'", quantity=product.quantity+1) 162 </a><a href="#h0-0-133" id="h0-0-133" class="i">+ print('gwtdafaakouttahere') 163 </a><a href="#h0-0-134" id="h0-0-134" class="i">+ else: 164 </a><a href="#h0-0-135" id="h0-0-135" class="i">+ db.insert('customerbag', sessionkey=session.sessionkey, product=i.id, price=i.price, quantity=1, timeadded=datetime.datetime.now()) 165 </a><a href="#h0-0-136" id="h0-0-136" class="i">+ 166 </a><a href="#h0-0-137" id="h0-0-137" class="i">+def productname(productid): 167 </a><a href="#h0-0-138" id="h0-0-138" class="i">+ try: 168 </a><a href="#h0-0-139" id="h0-0-139" class="i">+ name = db.query("SELECT name FROM products WHERE id='"+str(productid)+"';")[0] 169 </a><a href="#h0-0-140" id="h0-0-140" class="i">+ except: 170 </a><a href="#h0-0-141" id="h0-0-141" class="i">+ return '' 171 </a><a href="#h0-0-142" id="h0-0-142" class="i">+ return name.name 172 </a><a href="#h0-0-143" id="h0-0-143" class="i">+ 173 </a><a href="#h0-0-144" id="h0-0-144" class="i">+def getproduct(productid): 174 </a><a href="#h0-0-145" id="h0-0-145" class="i">+ try: 175 </a><a href="#h0-0-146" id="h0-0-146" class="i">+ product = db.query("SELECT * FROM products WHERE id='"+str(productid)+"';")[0] 176 </a><a href="#h0-0-147" id="h0-0-147" class="i">+ except: 177 </a><a href="#h0-0-148" id="h0-0-148" class="i">+ return '' 178 </a><a href="#h0-0-149" id="h0-0-149" class="i">+ return product 179 </a><a href="#h0-0-150" id="h0-0-150" class="i">+ 180 </a><a href="#h0-0-151" id="h0-0-151" class="i">+def getavailable(productid): 181 </a><a href="#h0-0-152" id="h0-0-152" class="i">+ try: 182 </a><a href="#h0-0-153" id="h0-0-153" class="i">+ name = db.query("SELECT available FROM products WHERE id='"+str(productid)+"';")[0] 183 </a><a href="#h0-0-154" id="h0-0-154" class="i">+ except: 184 </a><a href="#h0-0-155" id="h0-0-155" class="i">+ return '' 185 </a><a href="#h0-0-156" id="h0-0-156" class="i">+ return name.available 186 </a><a href="#h0-0-157" id="h0-0-157" class="i">+ 187 </a><a href="#h0-0-158" id="h0-0-158" class="i">+def checkforoldbags(): 188 </a><a href="#h0-0-159" id="h0-0-159" class="i">+ print('checking for old bags') 189 </a><a href="#h0-0-160" id="h0-0-160" class="i">+ bags = db.select('customerbag') 190 </a><a href="#h0-0-161" id="h0-0-161" class="i">+ for bag in bags: 191 </a><a href="#h0-0-162" id="h0-0-162" class="i">+ if datetime.datetime.now() - bag.timeadded > datetime.timedelta(hours=1): 192 </a><a href="#h0-0-163" id="h0-0-163" class="i">+ print(datetime.datetime.now() - bag.timeadded) 193 </a><a href="#h0-0-164" id="h0-0-164" class="i">+ print(datetime.timedelta(hours=1)) 194 </a><a href="#h0-0-165" id="h0-0-165" class="i">+ print("Fuck") 195 </a><a href="#h0-0-166" id="h0-0-166" class="i">+ product = getproduct(bag.product) 196 </a><a href="#h0-0-167" id="h0-0-167" class="i">+ print('found a bag at door! goddamit, got to put ' + str(bag.quantity) + ' x ' + product.name + ' back on the shelf') 197 </a><a href="#h0-0-168" id="h0-0-168" class="i">+ if product.available > 1: 198 </a><a href="#h0-0-169" id="h0-0-169" class="i">+ q = product.available + bag.quantity 199 </a><a href="#h0-0-170" id="h0-0-170" class="i">+ else: 200 </a><a href="#h0-0-171" id="h0-0-171" class="i">+ q = bag.quantity 201 </a><a href="#h0-0-172" id="h0-0-172" class="i">+ db.update('products', where="id='"+str(bag.product)+"'", available=str(q)) 202 </a><a href="#h0-0-173" id="h0-0-173" class="i">+ db.query("DELETE FROM customerbag WHERE sessionkey='" + bag.sessionkey + "'") 203 </a><a href="#h0-0-174" id="h0-0-174" class="i">+ 204 </a><a href="#h0-0-175" id="h0-0-175" class="i">+def checkavailable(): 205 </a><a href="#h0-0-176" id="h0-0-176" class="i">+ print('check items from availability') 206 </a><a href="#h0-0-177" id="h0-0-177" class="i">+ bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey + "'") 207 </a><a href="#h0-0-178" id="h0-0-178" class="i">+ for i in bag: 208 </a><a href="#h0-0-179" id="h0-0-179" class="i">+ q = getavailable(i.product) 209 </a><a href="#h0-0-180" id="h0-0-180" class="i">+ soldout = q - i.quantity 210 </a><a href="#h0-0-181" id="h0-0-181" class="i">+ if soldout < 0: 211 </a><a href="#h0-0-182" id="h0-0-182" class="i">+ web.seeother('/?error=soldout') 212 </a><a href="#h0-0-183" id="h0-0-183" class="i">+ else: 213 </a><a href="#h0-0-184" id="h0-0-184" class="i">+ return 214 </a><a href="#h0-0-185" id="h0-0-185" class="i">+ 215 </a><a href="#h0-0-186" id="h0-0-186" class="i">+def sold(): 216 </a><a href="#h0-0-187" id="h0-0-187" class="i">+ print('remove items from availability') 217 </a><a href="#h0-0-188" id="h0-0-188" class="i">+ bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey + "'") 218 </a><a href="#h0-0-189" id="h0-0-189" class="i">+ for i in bag: 219 </a><a href="#h0-0-190" id="h0-0-190" class="i">+ q = getavailable(i.product) 220 </a><a href="#h0-0-191" id="h0-0-191" class="i">+ soldout = q - i.quantity 221 </a><a href="#h0-0-192" id="h0-0-192" class="i">+ if soldout < 0: 222 </a><a href="#h0-0-193" id="h0-0-193" class="i">+ web.seeother('/?error=soldout') 223 </a><a href="#h0-0-194" id="h0-0-194" class="i">+ else: 224 </a><a href="#h0-0-195" id="h0-0-195" class="i">+ db.update('products', where="id='"+str(i.product)+"'", available=str(q - i.quantity)) 225 </a><a href="#h0-0-196" id="h0-0-196" class="i">+ 226 </a><a href="#h0-0-197" id="h0-0-197" class="i">+ 227 </a><a href="#h0-0-198" id="h0-0-198" class="i">+def organizepics(product): 228 </a><a href="#h0-0-199" id="h0-0-199" class="i">+ imgdir = basedir+'/public_html/static/img/' + str(product) + '/' 229 </a><a href="#h0-0-200" id="h0-0-200" class="i">+ imgdirlist = [imgdir, imgdir + 'web/', imgdir + 'thumb/'] 230 </a><a href="#h0-0-201" id="h0-0-201" class="i">+ for d in imgdirlist: 231 </a><a href="#h0-0-202" id="h0-0-202" class="i">+ pics = next(os.walk(d))[2] 232 </a><a href="#h0-0-203" id="h0-0-203" class="i">+ organized_nr = 0 233 </a><a href="#h0-0-204" id="h0-0-204" class="i">+ for s in sorted(pics): 234 </a><a href="#h0-0-205" id="h0-0-205" class="i">+ if '.jpeg' in s: 235 </a><a href="#h0-0-206" id="h0-0-206" class="i">+ #print(s) 236 </a><a href="#h0-0-207" id="h0-0-207" class="i">+ unorganized_nr = int(s[0:3]) 237 </a><a href="#h0-0-208" id="h0-0-208" class="i">+ if organized_nr == unorganized_nr: 238 </a><a href="#h0-0-209" id="h0-0-209" class="i">+ print('correcto pic numbering') 239 </a><a href="#h0-0-210" id="h0-0-210" class="i">+ pass 240 </a><a href="#h0-0-211" id="h0-0-211" class="i">+ if organized_nr != unorganized_nr: 241 </a><a href="#h0-0-212" id="h0-0-212" class="i">+ print('false, correcting pic from ' + str(unorganized_nr) + ' to ' + str(organized_nr)) 242 </a><a href="#h0-0-213" id="h0-0-213" class="i">+ mv = 'mv ' + d + str(unorganized_nr).zfill(3) + '.jpeg' 243 </a><a href="#h0-0-214" id="h0-0-214" class="i">+ mv2 = ' ' + d + str(organized_nr).zfill(3) + '.jpeg' 244 </a><a href="#h0-0-215" id="h0-0-215" class="i">+ os.system(mv + mv2) 245 </a><a href="#h0-0-216" id="h0-0-216" class="i">+ organized_nr += 1 246 </a><a href="#h0-0-217" id="h0-0-217" class="i">+ 247 </a><a href="#h0-0-218" id="h0-0-218" class="i">+class index(): 248 </a><a href="#h0-0-219" id="h0-0-219" class="i">+ def GET(self): 249 </a><a href="#h0-0-220" id="h0-0-220" class="i">+ checkforoldbags() 250 </a><a href="#h0-0-221" id="h0-0-221" class="i">+ i = web.input(dropitem=None, putinbag=None) 251 </a><a href="#h0-0-222" id="h0-0-222" class="i">+ if session.sessionkey == 0: 252 </a><a href="#h0-0-223" id="h0-0-223" class="i">+ session.sessionkey = hashlib.sha256(str(random.getrandbits(256)).encode('utf-8')).hexdigest() 253 </a><a href="#h0-0-224" id="h0-0-224" class="i">+ if i.dropitem != None: 254 </a><a href="#h0-0-225" id="h0-0-225" class="i">+ session.bag = dropitems(int(i.dropitem)) 255 </a><a href="#h0-0-226" id="h0-0-226" class="i">+ print(session.bag) 256 </a><a href="#h0-0-227" id="h0-0-227" class="i">+ if i.putinbag != None: 257 </a><a href="#h0-0-228" id="h0-0-228" class="i">+ addtobag(i.putinbag) 258 </a><a href="#h0-0-229" id="h0-0-229" class="i">+ return web.seeother('/#' + i.putinbag) 259 </a><a href="#h0-0-230" id="h0-0-230" class="i">+ print('Cyberpunk cafe') 260 </a><a href="#h0-0-231" id="h0-0-231" class="i">+ #print(session.bag) 261 </a><a href="#h0-0-232" id="h0-0-232" class="i">+ b = BtcConverter() 262 </a><a href="#h0-0-233" id="h0-0-233" class="i">+ listproducts = db.query("SELECT * FROM products ORDER BY priority DESC") 263 </a><a href="#h0-0-234" id="h0-0-234" class="i">+ imgfiles = [] 264 </a><a href="#h0-0-235" id="h0-0-235" class="i">+ products = [] 265 </a><a href="#h0-0-236" id="h0-0-236" class="i">+ # Search product images 266 </a><a href="#h0-0-237" id="h0-0-237" class="i">+ for i in listproducts: 267 </a><a href="#h0-0-238" id="h0-0-238" class="i">+ productimages = [''] 268 </a><a href="#h0-0-239" id="h0-0-239" class="i">+ imgdir = staticdir + 'img/' + str(i.id) + '/web/' 269 </a><a href="#h0-0-240" id="h0-0-240" class="i">+ try: 270 </a><a href="#h0-0-241" id="h0-0-241" class="i">+ productimages = sorted(os.listdir(imgdir)) 271 </a><a href="#h0-0-242" id="h0-0-242" class="i">+ if len(productimages) == 0: 272 </a><a href="#h0-0-243" id="h0-0-243" class="i">+ productimages = [''] 273 </a><a href="#h0-0-244" id="h0-0-244" class="i">+ print(productimages) 274 </a><a href="#h0-0-245" id="h0-0-245" class="i">+ except FileNotFoundError: 275 </a><a href="#h0-0-246" id="h0-0-246" class="i">+ print('No product images') 276 </a><a href="#h0-0-247" id="h0-0-247" class="i">+ pass 277 </a><a href="#h0-0-248" id="h0-0-248" class="i">+ i.update({'images':productimages}) 278 </a><a href="#h0-0-249" id="h0-0-249" class="i">+ products.append(i) 279 </a><a href="#h0-0-250" id="h0-0-250" class="i">+ try: 280 </a><a href="#h0-0-251" id="h0-0-251" class="i">+ bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"';") 281 </a><a href="#h0-0-252" id="h0-0-252" class="i">+ except: 282 </a><a href="#h0-0-253" id="h0-0-253" class="i">+ bag = [] 283 </a><a href="#h0-0-254" id="h0-0-254" class="i">+ return render.index(products, b, bag, str, int, float, session.sessionkey, productname) 284 </a><a href="#h0-0-255" id="h0-0-255" class="i">+ 285 </a><a href="#h0-0-256" id="h0-0-256" class="i">+class putinbag: 286 </a><a href="#h0-0-257" id="h0-0-257" class="i">+ def GET(self, p): 287 </a><a href="#h0-0-258" id="h0-0-258" class="i">+ addtobag(p) 288 </a><a href="#h0-0-259" id="h0-0-259" class="i">+ raise web.seeother('/') 289 </a><a href="#h0-0-260" id="h0-0-260" class="i">+ 290 </a><a href="#h0-0-261" id="h0-0-261" class="i">+class dropitem(): 291 </a><a href="#h0-0-262" id="h0-0-262" class="i">+ def GET(self, d): 292 </a><a href="#h0-0-263" id="h0-0-263" class="i">+ p = web.input() 293 </a><a href="#h0-0-264" id="h0-0-264" class="i">+ i = 0 294 </a><a href="#h0-0-265" id="h0-0-265" class="i">+ dropitems(int(d)) 295 </a><a href="#h0-0-266" id="h0-0-266" class="i">+ return web.seeother('/#'+d) 296 </a><a href="#h0-0-267" id="h0-0-267" class="i">+ 297 </a><a href="#h0-0-268" id="h0-0-268" class="i">+class bigpic(): 298 </a><a href="#h0-0-269" id="h0-0-269" class="i">+ def GET(self, i): 299 </a><a href="#h0-0-270" id="h0-0-270" class="i">+ print('faaaakyeee ' + i) 300 </a><a href="#h0-0-271" id="h0-0-271" class="i">+ p = web.input(pic=None) 301 </a><a href="#h0-0-272" id="h0-0-272" class="i">+ if p.pic != None: 302 </a><a href="#h0-0-273" id="h0-0-273" class="i">+ return render.bigpic(p.pic, i) 303 </a><a href="#h0-0-274" id="h0-0-274" class="i">+ 304 </a><a href="#h0-0-275" id="h0-0-275" class="i">+class checkout: 305 </a><a href="#h0-0-276" id="h0-0-276" class="i">+ t = [] 306 </a><a href="#h0-0-277" id="h0-0-277" class="i">+ shippingcountries = db.select('shipping', what='country', order='country ASC') 307 </a><a href="#h0-0-278" id="h0-0-278" class="i">+ shippingcountries = list(shippingcountries) 308 </a><a href="#h0-0-279" id="h0-0-279" class="i">+ t.append('NO-SHIPPING') 309 </a><a href="#h0-0-280" id="h0-0-280" class="i">+ for i in shippingcountries: 310 </a><a href="#h0-0-281" id="h0-0-281" class="i">+ if i.country != 'NO-SHIPPING': 311 </a><a href="#h0-0-282" id="h0-0-282" class="i">+ t.append(i.country) 312 </a><a href="#h0-0-283" id="h0-0-283" class="i">+ form = web.form.Form( 313 </a><a href="#h0-0-284" id="h0-0-284" class="i">+ web.form.Dropdown('country', t, web.form.notnull, description="Country"), 314 </a><a href="#h0-0-285" id="h0-0-285" class="i">+ web.form.Textbox('firstname', web.form.notnull, description="First Name:"), 315 </a><a href="#h0-0-286" id="h0-0-286" class="i">+ web.form.Textbox('lastname', web.form.notnull, description="Last Name:"), 316 </a><a href="#h0-0-287" id="h0-0-287" class="i">+ web.form.Textbox('address', web.form.notnull, description="Shipping Address:"), 317 </a><a href="#h0-0-288" id="h0-0-288" class="i">+ web.form.Textbox('town', web.form.notnull, description="Town / City:"), 318 </a><a href="#h0-0-289" id="h0-0-289" class="i">+ web.form.Textbox('postalcode', web.form.regexp('\d+', 'number thanx!'), web.form.notnull, description="Postalcode / zip"), 319 </a><a href="#h0-0-290" id="h0-0-290" class="i">+ web.form.Textbox('email', web.form.notnull, description="Email:"), 320 </a><a href="#h0-0-291" id="h0-0-291" class="i">+ web.form.Button('Calculate shipping cost')) 321 </a><a href="#h0-0-292" id="h0-0-292" class="i">+ def GET(self, pending_key): 322 </a><a href="#h0-0-293" id="h0-0-293" class="i">+ #checkavailable() 323 </a><a href="#h0-0-294" id="h0-0-294" class="i">+ checkoutform = self.form() 324 </a><a href="#h0-0-295" id="h0-0-295" class="i">+ if pending_key: 325 </a><a href="#h0-0-296" id="h0-0-296" class="i">+ oldinfo = db.select('pending', where="invoice_key='" + pending_key + "'", what='country, firstname, lastname, address, town, postalcode, email') 326 </a><a href="#h0-0-297" id="h0-0-297" class="i">+ oldinfo = oldinfo[0] 327 </a><a href="#h0-0-298" id="h0-0-298" class="i">+ checkoutform.fill(country=oldinfo.country, firstname=oldinfo.firstname, lastname=oldinfo.lastname, address=oldinfo.address, town=oldinfo.town, postalcode=oldinfo.postalcode, email=oldinfo.email) 328 </a><a href="#h0-0-299" id="h0-0-299" class="i">+ b = BtcConverter() 329 </a><a href="#h0-0-300" id="h0-0-300" class="i">+ bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"';") 330 </a><a href="#h0-0-301" id="h0-0-301" class="i">+ return render.checkout(checkoutform, bag, b, productname, float) 331 </a><a href="#h0-0-302" id="h0-0-302" class="i">+ def POST(self, pending_key): 332 </a><a href="#h0-0-303" id="h0-0-303" class="i">+ checkoutform = self.form() 333 </a><a href="#h0-0-304" id="h0-0-304" class="i">+ i = web.input() 334 </a><a href="#h0-0-305" id="h0-0-305" class="i">+ if i.country != 'NO-SHIPPING': 335 </a><a href="#h0-0-306" id="h0-0-306" class="i">+ if not checkoutform.validates(): 336 </a><a href="#h0-0-307" id="h0-0-307" class="i">+ b = BtcConverter() 337 </a><a href="#h0-0-308" id="h0-0-308" class="i">+ return render.checkout(checkoutform, session.bag, b) 338 </a><a href="#h0-0-309" id="h0-0-309" class="i">+ if pending_key: 339 </a><a href="#h0-0-310" id="h0-0-310" class="i">+ db.update('pending', where="invoice_key='" + pending_key +"'", country=i.country, firstname=i.firstname, lastname=i.lastname, address=i.address, town=i.town, postalcode=i.postalcode, email=i.email, dateadded=datetime.datetime.now()) 340 </a><a href="#h0-0-311" id="h0-0-311" class="i">+ else: 341 </a><a href="#h0-0-312" id="h0-0-312" class="i">+ pending_key = session.sessionkey 342 </a><a href="#h0-0-313" id="h0-0-313" class="i">+ db.insert('pending', invoice_key=pending_key, country=i.country, firstname=i.firstname, lastname=i.lastname, address=i.address, town=i.town, postalcode=i.postalcode, email=i.email, dateadded=datetime.datetime.now()) 343 </a><a href="#h0-0-314" id="h0-0-314" class="i">+ raise web.seeother('/pending/' + pending_key) 344 </a><a href="#h0-0-315" id="h0-0-315" class="i">+ 345 </a><a href="#h0-0-316" id="h0-0-316" class="i">+class pending: 346 </a><a href="#h0-0-317" id="h0-0-317" class="i">+ form = web.form.Form( 347 </a><a href="#h0-0-318" id="h0-0-318" class="i">+ web.form.Dropdown('payment', ['Bitcoin Lightning', 'Bitcoin'], web.form.notnull, description="Select payment method"), 348 </a><a href="#h0-0-319" id="h0-0-319" class="i">+ web.form.Button('Pay')) 349 </a><a href="#h0-0-320" id="h0-0-320" class="i">+ def GET(self, pending_key): 350 </a><a href="#h0-0-321" id="h0-0-321" class="i">+ #checkavailable() 351 </a><a href="#h0-0-322" id="h0-0-322" class="i">+ pendingform = self.form() 352 </a><a href="#h0-0-323" id="h0-0-323" class="i">+ if pending_key: 353 </a><a href="#h0-0-324" id="h0-0-324" class="i">+ pendinginfo = db.select('pending', where="invoice_key='" + pending_key + "'", what='country, firstname, lastname, address, town, postalcode, email') 354 </a><a href="#h0-0-325" id="h0-0-325" class="i">+ pendinginfo = pendinginfo[0] 355 </a><a href="#h0-0-326" id="h0-0-326" class="i">+ shippinginfo = db.select('shipping', where="country='" + pendinginfo.country + "'", what='price, days') 356 </a><a href="#h0-0-327" id="h0-0-327" class="i">+ shippinginfo = shippinginfo[0] 357 </a><a href="#h0-0-328" id="h0-0-328" class="i">+ b = BtcConverter() 358 </a><a href="#h0-0-329" id="h0-0-329" class="i">+ bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"';") 359 </a><a href="#h0-0-330" id="h0-0-330" class="i">+ return render.pending(pending_key, pendingform, pendinginfo, shippinginfo, bag, b, productname, float) 360 </a><a href="#h0-0-331" id="h0-0-331" class="i">+ def POST(self, pending_key): 361 </a><a href="#h0-0-332" id="h0-0-332" class="i">+ pendingform = self.form() 362 </a><a href="#h0-0-333" id="h0-0-333" class="i">+ if pending_key: 363 </a><a href="#h0-0-334" id="h0-0-334" class="i">+ pendinginfo = db.select('pending', where="invoice_key='" + pending_key + "'", what='country, firstname, lastname, address, town, postalcode, email') 364 </a><a href="#h0-0-335" id="h0-0-335" class="i">+ pendinginfo = pendinginfo[0] 365 </a><a href="#h0-0-336" id="h0-0-336" class="i">+ shippinginfo = db.select('shipping', where="country='" + pendinginfo.country + "'", what='price, days') 366 </a><a href="#h0-0-337" id="h0-0-337" class="i">+ shippinginfo = shippinginfo[0] 367 </a><a href="#h0-0-338" id="h0-0-338" class="i">+ i = web.input() 368 </a><a href="#h0-0-339" id="h0-0-339" class="i">+ #if session.bag != []: 369 </a><a href="#h0-0-340" id="h0-0-340" class="i">+ totalamount = 0 370 </a><a href="#h0-0-341" id="h0-0-341" class="i">+ description = '' 371 </a><a href="#h0-0-342" id="h0-0-342" class="i">+ bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"';") 372 </a><a href="#h0-0-343" id="h0-0-343" class="i">+ comma = '' 373 </a><a href="#h0-0-344" id="h0-0-344" class="i">+ for s in bag: 374 </a><a href="#h0-0-345" id="h0-0-345" class="i">+ totalamount += s.price 375 </a><a href="#h0-0-346" id="h0-0-346" class="i">+ description += comma + str(s.quantity) + ' x ' + productname(s.product) 376 </a><a href="#h0-0-347" id="h0-0-347" class="i">+ comma = ', ' 377 </a><a href="#h0-0-348" id="h0-0-348" class="i">+ totalamount += shippinginfo.price 378 </a><a href="#h0-0-349" id="h0-0-349" class="i">+ b = BtcConverter() 379 </a><a href="#h0-0-350" id="h0-0-350" class="i">+ totsats = int(b.convert_to_btc(float(totalamount/100), 'EUR') * 100000000) 380 </a><a href="#h0-0-351" id="h0-0-351" class="i">+ totbtc = int(b.convert_to_btc(float(totalamount/100), 'EUR')) 381 </a><a href="#h0-0-352" id="h0-0-352" class="i">+ print(str(totalamount) + ' | ' + description) 382 </a><a href="#h0-0-353" id="h0-0-353" class="i">+ print(str(totsats) + ' | ' + description) 383 </a><a href="#h0-0-354" id="h0-0-354" class="i">+ #else: 384 </a><a href="#h0-0-355" id="h0-0-355" class="i">+ # web.seeother('/') 385 </a><a href="#h0-0-356" id="h0-0-356" class="i">+ #make lightning invoice 386 </a><a href="#h0-0-357" id="h0-0-357" class="i">+ invoice = createinvoice(totsats, description, pending_key) 387 </a><a href="#h0-0-358" id="h0-0-358" class="i">+ callsubprocess('qrencode -s 5 -o '+ staticdir + 'qr/' + invoice['id']+'.png ' + invoice['payreq']) 388 </a><a href="#h0-0-359" id="h0-0-359" class="i">+ #make bitcoin address 389 </a><a href="#h0-0-360" id="h0-0-360" class="i">+ bitcoinrpc = AuthServiceProxy(rpcauth) 390 </a><a href="#h0-0-361" id="h0-0-361" class="i">+ newaddress = bitcoinrpc.getnewaddress('GetDaFuckOuttaHere Butik') 391 </a><a href="#h0-0-362" id="h0-0-362" class="i">+ bitcoinrpc = None 392 </a><a href="#h0-0-363" id="h0-0-363" class="i">+ btcuri = 'bitcoin:' + newaddress + '?amount=' + str(totbtc) + '&label=' + description 393 </a><a href="#h0-0-364" id="h0-0-364" class="i">+ callsubprocess('qrencode -s 5 -o '+ staticdir + 'qr/' + newaddress +'.png ' + btcuri) 394 </a><a href="#h0-0-365" id="h0-0-365" class="i">+ try: 395 </a><a href="#h0-0-366" id="h0-0-366" class="i">+ db.query("DELETE FROM invoices WHERE invoice_key='" + session.sessionkey +"';") 396 </a><a href="#h0-0-367" id="h0-0-367" class="i">+ except: 397 </a><a href="#h0-0-368" id="h0-0-368" class="i">+ print('no old invoices to delete') 398 </a><a href="#h0-0-369" id="h0-0-369" class="i">+ db.insert('invoices', invoice_key=pending_key, btc=newaddress, ln=invoice['id'], products=description, payment=i.payment, amount=totalamount, totsats=totsats, timestamp=time.strftime('%Y-%m-%d %H:%M:%S')) 399 </a><a href="#h0-0-370" id="h0-0-370" class="i">+ # send mail to op 400 </a><a href="#h0-0-371" id="h0-0-371" class="i">+ msg = 'You got a new order, from ' + pendinginfo.firstname + ' ' + pendinginfo.lastname + ' from ' + pendinginfo.country + ' email: ' + pendinginfo.email + ' this dude wantz ' + description + ' for ' + str(int(totalamount/100)) + '€ ' + ' with ' + i.payment 401 </a><a href="#h0-0-372" id="h0-0-372" class="i">+ sendmail(webmaster, 'GetDaFuckOuttaHere Shop', msg) 402 </a><a href="#h0-0-373" id="h0-0-373" class="i">+ # send mail to customer 403 </a><a href="#h0-0-374" id="h0-0-374" class="i">+ if i.payment == 'Bitcoin': 404 </a><a href="#h0-0-375" id="h0-0-375" class="i">+ paymentlink = 'paybtc/' 405 </a><a href="#h0-0-376" id="h0-0-376" class="i">+ if i.payment == 'Bitcoin Lightning': 406 </a><a href="#h0-0-377" id="h0-0-377" class="i">+ paymentlink = 'payln/' 407 </a><a href="#h0-0-378" id="h0-0-378" class="i">+ if pendinginfo.email != '': 408 </a><a href="#h0-0-379" id="h0-0-379" class="i">+ msg = "Thank you for ordering " + description + " at GetDaFuckOuttaHere Shop, we'll be processing your order as soon as possible and send it to " + pendinginfo.firstname + ' ' + pendinginfo.lastname + ', ' + pendinginfo.address + ', ' + str(pendinginfo.postalcode) + ', ' + pendinginfo.town + ', ' + pendinginfo.country + '. To pay/view status of your order please visit ' + baseurl + paymentlink + pending_key 409 </a><a href="#h0-0-380" id="h0-0-380" class="i">+ sendmail(pendinginfo.email, 'GetDaFuckOuttaHere Shop', msg) 410 </a><a href="#h0-0-381" id="h0-0-381" class="i">+ if i.payment == 'Bitcoin': 411 </a><a href="#h0-0-382" id="h0-0-382" class="i">+ return web.seeother('/paybtc/' + pending_key) 412 </a><a href="#h0-0-383" id="h0-0-383" class="i">+ if i.payment == 'Bitcoin Lightning': 413 </a><a href="#h0-0-384" id="h0-0-384" class="i">+ return web.seeother('/payln/' + pending_key) 414 </a><a href="#h0-0-385" id="h0-0-385" class="i">+ else: 415 </a><a href="#h0-0-386" id="h0-0-386" class="i">+ return web.seeother('/') 416 </a><a href="#h0-0-387" id="h0-0-387" class="i">+ 417 </a><a href="#h0-0-388" id="h0-0-388" class="i">+class payln: 418 </a><a href="#h0-0-389" id="h0-0-389" class="i">+ def GET(self, invoice_key): 419 </a><a href="#h0-0-390" id="h0-0-390" class="i">+ #checkavailable() 420 </a><a href="#h0-0-391" id="h0-0-391" class="i">+ invoice = db.select('invoices', where="invoice_key='" + invoice_key + "'", what='invoice_key, btc, ln, products, payment, amount, totsats, timestamp, status, datepaid, dateshipped')[0] 421 </a><a href="#h0-0-392" id="h0-0-392" class="i">+ lninvoice = getinvoice(invoice.ln) 422 </a><a href="#h0-0-393" id="h0-0-393" class="i">+ bag = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"';") 423 </a><a href="#h0-0-394" id="h0-0-394" class="i">+ if invoice_key == session.sessionkey: 424 </a><a href="#h0-0-395" id="h0-0-395" class="i">+ return render.payln(lninvoice, invoice, bag, productname, float) 425 </a><a href="#h0-0-396" id="h0-0-396" class="i">+ else: 426 </a><a href="#h0-0-397" id="h0-0-397" class="i">+ raise web.seeother('/?error=timeout') 427 </a><a href="#h0-0-398" id="h0-0-398" class="i">+ def POST(self, id): 428 </a><a href="#h0-0-399" id="h0-0-399" class="i">+ data = web.data() 429 </a><a href="#h0-0-400" id="h0-0-400" class="i">+ data = data.decode('utf8').replace("'", '"') 430 </a><a href="#h0-0-401" id="h0-0-401" class="i">+ data = json.loads(data) 431 </a><a href="#h0-0-402" id="h0-0-402" class="i">+ print(data) 432 </a><a href="#h0-0-403" id="h0-0-403" class="i">+ if data['status'] == 'paid': 433 </a><a href="#h0-0-404" id="h0-0-404" class="i">+ print("Hurray it worked") 434 </a><a href="#h0-0-405" id="h0-0-405" class="i">+ sold() 435 </a><a href="#h0-0-406" id="h0-0-406" class="i">+ return render.thankyou(id) 436 </a><a href="#h0-0-407" id="h0-0-407" class="i">+ 437 </a><a href="#h0-0-408" id="h0-0-408" class="i">+class paybtc: 438 </a><a href="#h0-0-409" id="h0-0-409" class="i">+ def GET(self, invoice_key): 439 </a><a href="#h0-0-410" id="h0-0-410" class="i">+ invoice = db.select('invoices', where="invoice_key='" + invoice_key + "'", what='invoice_key, btc, ln, products, payment, amount, totsats, timestamp, status, datepaid, dateshipped')[0] 440 </a><a href="#h0-0-411" id="h0-0-411" class="i">+ totbtc = float(invoice.totsats * 0.00000001) 441 </a><a href="#h0-0-412" id="h0-0-412" class="i">+ btcaddress = invoice.btc 442 </a><a href="#h0-0-413" id="h0-0-413" class="i">+ btcuri = 'bitcoin:' + btcaddress + '?amount=' + str(totbtc) + '&label=' + invoice.products 443 </a><a href="#h0-0-414" id="h0-0-414" class="i">+ bitcoinrpc = AuthServiceProxy(rpcauth) 444 </a><a href="#h0-0-415" id="h0-0-415" class="i">+ showpayment = bitcoinrpc.listreceivedbyaddress(0, True, True, btcaddress) 445 </a><a href="#h0-0-416" id="h0-0-416" class="i">+ bitcoinrpc = None 446 </a><a href="#h0-0-417" id="h0-0-417" class="i">+ if showpayment: 447 </a><a href="#h0-0-418" id="h0-0-418" class="i">+ for i in showpayment: 448 </a><a href="#h0-0-419" id="h0-0-419" class="i">+ confirmations = int(i['confirmations']) 449 </a><a href="#h0-0-420" id="h0-0-420" class="i">+ print(str(confirmations)) 450 </a><a href="#h0-0-421" id="h0-0-421" class="i">+ if invoice.datepaid == None and confirmations > 6: 451 </a><a href="#h0-0-422" id="h0-0-422" class="i">+ msg = 'GetDaFuckOuttaHere order update! someone sent you Bitcoin! ' + baseurl + '/paybtc/' + invoice.invoice_key 452 </a><a href="#h0-0-423" id="h0-0-423" class="i">+ print(msg) 453 </a><a href="#h0-0-424" id="h0-0-424" class="i">+ sendmail(webmaster, 'GetDaFuckOuttaHere Shop', msg) 454 </a><a href="#h0-0-425" id="h0-0-425" class="i">+ db.update('invoices', where="invoice_key='" + invoice.invoice_key + "'", status='paid', datepaid=time.strftime('%Y-%m-%d %H:%M:%S')) 455 </a><a href="#h0-0-426" id="h0-0-426" class="i">+ return render.paybtc(invoice, btcaddress, btcuri, showpayment) 456 </a><a href="#h0-0-427" id="h0-0-427" class="i">+ 457 </a><a href="#h0-0-428" id="h0-0-428" class="i">+class payments: 458 </a><a href="#h0-0-429" id="h0-0-429" class="i">+ def GET(self): 459 </a><a href="#h0-0-430" id="h0-0-430" class="i">+ w = web.input() 460 </a><a href="#h0-0-431" id="h0-0-431" class="i">+ if w: 461 </a><a href="#h0-0-432" id="h0-0-432" class="i">+ db.update('invoices', where="invoice_key='" + w.key + "'", status=w.status) 462 </a><a href="#h0-0-433" id="h0-0-433" class="i">+ #get the right invoice send mail 463 </a><a href="#h0-0-434" id="h0-0-434" class="i">+ customer = db.select('pending', where="invoice_key='" + w.key + "'", what='country, firstname, lastname, address, town, postalcode, email')[0] 464 </a><a href="#h0-0-435" id="h0-0-435" class="i">+ payment = db.select('invoices', where="invoice_key='" + w.key + "'", what='btc, ln, invoice_key, products, payment, amount, totsats, timestamp, status, datepaid, dateshipped')[0] 465 </a><a href="#h0-0-436" id="h0-0-436" class="i">+ if payment.payment == 'Bitcoin': 466 </a><a href="#h0-0-437" id="h0-0-437" class="i">+ paylink = 'paybtc/' 467 </a><a href="#h0-0-438" id="h0-0-438" class="i">+ elif payment.payment == 'Bitcoin Lightning': 468 </a><a href="#h0-0-439" id="h0-0-439" class="i">+ paylink = 'payln/' 469 </a><a href="#h0-0-440" id="h0-0-440" class="i">+ if w.status == 'thankyou': 470 </a><a href="#h0-0-441" id="h0-0-441" class="i">+ msg="Hi " + customer.firstname + " " + customer.lastname + ", thank you for ordering. You can track the status of your order at " + baseurl + paylink + payment.invoice_key 471 </a><a href="#h0-0-442" id="h0-0-442" class="i">+ sendmail(customer.email, 'GetDaFuckOuttaHere Shop, a thank you!', msg) 472 </a><a href="#h0-0-443" id="h0-0-443" class="i">+ elif w.status == 'shipped': 473 </a><a href="#h0-0-444" id="h0-0-444" class="i">+ msg="Hi " + customer.firstname + " " + customer.lastname + ", your order has been shipped!. You can track the status of your order at " + baseurl + paylink + payment.invoice_key 474 </a><a href="#h0-0-445" id="h0-0-445" class="i">+ sendmail(customer.email, 'GetDaFuckOuttaHere Shop, order shipped!', msg) 475 </a><a href="#h0-0-446" id="h0-0-446" class="i">+ paymentdict = {} 476 </a><a href="#h0-0-447" id="h0-0-447" class="i">+ listpayments = [] 477 </a><a href="#h0-0-448" id="h0-0-448" class="i">+ payments = db.select('invoices', what='btc, ln, invoice_key, products, payment, amount, totsats, timestamp, status, datepaid, dateshipped', order='timestamp DESC') 478 </a><a href="#h0-0-449" id="h0-0-449" class="i">+ for i in payments: 479 </a><a href="#h0-0-450" id="h0-0-450" class="i">+ pending = db.select('pending', where="invoice_key='" + i.invoice_key + "'", what='country, firstname, lastname, address, town, postalcode, email') 480 </a><a href="#h0-0-451" id="h0-0-451" class="i">+ i.update(pending[0]) 481 </a><a href="#h0-0-452" id="h0-0-452" class="i">+ listpayments.append(i) 482 </a><a href="#h0-0-453" id="h0-0-453" class="i">+ return renderop.payments(listpayments) 483 </a><a href="#h0-0-454" id="h0-0-454" class="i">+ 484 </a><a href="#h0-0-455" id="h0-0-455" class="i">+class payment: 485 </a><a href="#h0-0-456" id="h0-0-456" class="i">+ def GET(self, invoice_key): 486 </a><a href="#h0-0-457" id="h0-0-457" class="i">+ id = db.where('invoices', invoice_key=invoice_key)[0]['ln'] 487 </a><a href="#h0-0-458" id="h0-0-458" class="i">+ invoice = getinvoice(id) 488 </a><a href="#h0-0-459" id="h0-0-459" class="i">+ return render.payment(invoice) 489 </a><a href="#h0-0-460" id="h0-0-460" class="i">+ 490 </a><a href="#h0-0-461" id="h0-0-461" class="i">+class thankyou: 491 </a><a href="#h0-0-462" id="h0-0-462" class="i">+ def GET(self, id): 492 </a><a href="#h0-0-463" id="h0-0-463" class="i">+ return render.thankyou(id) 493 </a><a href="#h0-0-464" id="h0-0-464" class="i">+ 494 </a><a href="#h0-0-465" id="h0-0-465" class="i">+class login: 495 </a><a href="#h0-0-466" id="h0-0-466" class="i">+ form = web.form.Form( 496 </a><a href="#h0-0-467" id="h0-0-467" class="i">+ web.form.Textbox('user', web.form.notnull, description="User"), 497 </a><a href="#h0-0-468" id="h0-0-468" class="i">+ web.form.Password('password', web.form.notnull, description="Passcode"), 498 </a><a href="#h0-0-469" id="h0-0-469" class="i">+ web.form.Button('Login')) 499 </a><a href="#h0-0-470" id="h0-0-470" class="i">+ def GET(self): 500 </a><a href="#h0-0-471" id="h0-0-471" class="i">+ if not logged(): 501 </a><a href="#h0-0-472" id="h0-0-472" class="i">+ loginform = self.form() 502 </a><a href="#h0-0-473" id="h0-0-473" class="i">+ return render.login(loginform) 503 </a><a href="#h0-0-474" id="h0-0-474" class="i">+ else: 504 </a><a href="#h0-0-475" id="h0-0-475" class="i">+ raise web.seeother('/op') 505 </a><a href="#h0-0-476" id="h0-0-476" class="i">+ def POST(self): 506 </a><a href="#h0-0-477" id="h0-0-477" class="i">+ loginform = self.form() 507 </a><a href="#h0-0-478" id="h0-0-478" class="i">+ if not loginform.validates(): 508 </a><a href="#h0-0-479" id="h0-0-479" class="i">+ return render.login(loginform) 509 </a><a href="#h0-0-480" id="h0-0-480" class="i">+ else: 510 </a><a href="#h0-0-481" id="h0-0-481" class="i">+ i = web.input() 511 </a><a href="#h0-0-482" id="h0-0-482" class="i">+ if (i.user,i.password) in allowed: 512 </a><a href="#h0-0-483" id="h0-0-483" class="i">+ session.login = 1 513 </a><a href="#h0-0-484" id="h0-0-484" class="i">+ raise web.seeother('/op') 514 </a><a href="#h0-0-485" id="h0-0-485" class="i">+ else: 515 </a><a href="#h0-0-486" id="h0-0-486" class="i">+ return render.login(loginform) 516 </a><a href="#h0-0-487" id="h0-0-487" class="i">+ 517 </a><a href="#h0-0-488" id="h0-0-488" class="i">+class logout: 518 </a><a href="#h0-0-489" id="h0-0-489" class="i">+ def GET(self): 519 </a><a href="#h0-0-490" id="h0-0-490" class="i">+ session.login = 0 520 </a><a href="#h0-0-491" id="h0-0-491" class="i">+ raise web.seeother('/') 521 </a><a href="#h0-0-492" id="h0-0-492" class="i">+ 522 </a><a href="#h0-0-493" id="h0-0-493" class="i">+class op: 523 </a><a href="#h0-0-494" id="h0-0-494" class="i">+ def GET(self): 524 </a><a href="#h0-0-495" id="h0-0-495" class="i">+ if logged(): 525 </a><a href="#h0-0-496" id="h0-0-496" class="i">+ return renderop.operator() 526 </a><a href="#h0-0-497" id="h0-0-497" class="i">+ else: 527 </a><a href="#h0-0-498" id="h0-0-498" class="i">+ raise web.seeother('/login') 528 </a><a href="#h0-0-499" id="h0-0-499" class="i">+ 529 </a><a href="#h0-0-500" id="h0-0-500" class="i">+class categories: 530 </a><a href="#h0-0-501" id="h0-0-501" class="i">+ form = web.form.Form( 531 </a><a href="#h0-0-502" id="h0-0-502" class="i">+ web.form.Textbox('category', web.form.notnull, description="Add Category:"), 532 </a><a href="#h0-0-503" id="h0-0-503" class="i">+ web.form.Button('Add')) 533 </a><a href="#h0-0-504" id="h0-0-504" class="i">+ def GET(self): 534 </a><a href="#h0-0-505" id="h0-0-505" class="i">+ if logged(): 535 </a><a href="#h0-0-506" id="h0-0-506" class="i">+ i = web.input(delete=None) 536 </a><a href="#h0-0-507" id="h0-0-507" class="i">+ if i.delete: 537 </a><a href="#h0-0-508" id="h0-0-508" class="i">+ db.delete('categories', where='id='+i.delete) 538 </a><a href="#h0-0-509" id="h0-0-509" class="i">+ listcategories = db.query("SELECT * FROM categories ORDER BY id DESC") 539 </a><a href="#h0-0-510" id="h0-0-510" class="i">+ addcategory = self.form() 540 </a><a href="#h0-0-511" id="h0-0-511" class="i">+ return renderop.categories(listcategories,addcategory) 541 </a><a href="#h0-0-512" id="h0-0-512" class="i">+ else: 542 </a><a href="#h0-0-513" id="h0-0-513" class="i">+ raise web.seeother('/login') 543 </a><a href="#h0-0-514" id="h0-0-514" class="i">+ def POST(self): 544 </a><a href="#h0-0-515" id="h0-0-515" class="i">+ addcategory = self.form() 545 </a><a href="#h0-0-516" id="h0-0-516" class="i">+ i = web.input() 546 </a><a href="#h0-0-517" id="h0-0-517" class="i">+ db.insert('categories', category=i.category) 547 </a><a href="#h0-0-518" id="h0-0-518" class="i">+ raise web.seeother('/categories') 548 </a><a href="#h0-0-519" id="h0-0-519" class="i">+ 549 </a><a href="#h0-0-520" id="h0-0-520" class="i">+ 550 </a><a href="#h0-0-521" id="h0-0-521" class="i">+class products: 551 </a><a href="#h0-0-522" id="h0-0-522" class="i">+ listcategories = db.query("SELECT * FROM categories ORDER BY id DESC") 552 </a><a href="#h0-0-523" id="h0-0-523" class="i">+ p = [] 553 </a><a href="#h0-0-524" id="h0-0-524" class="i">+ for i in listcategories: 554 </a><a href="#h0-0-525" id="h0-0-525" class="i">+ p.append(i.category) 555 </a><a href="#h0-0-526" id="h0-0-526" class="i">+ #p = listcategories[0] 556 </a><a href="#h0-0-527" id="h0-0-527" class="i">+ form = web.form.Form( 557 </a><a href="#h0-0-528" id="h0-0-528" class="i">+ web.form.Dropdown('category', p, web.form.notnull, description="Category:"), 558 </a><a href="#h0-0-529" id="h0-0-529" class="i">+ web.form.Textbox('name', web.form.notnull, description="Name:"), 559 </a><a href="#h0-0-530" id="h0-0-530" class="i">+ web.form.Textarea('description', web.form.notnull, description="Description:"), 560 </a><a href="#h0-0-531" id="h0-0-531" class="i">+ web.form.Textbox('price', web.form.regexp('\d+', 'number thanx!'), web.form.notnull, description="Price in cents"), 561 </a><a href="#h0-0-532" id="h0-0-532" class="i">+ web.form.Textbox('available', web.form.notnull, web.form.regexp('\d+', 'number dumbass!'), description="Available"), 562 </a><a href="#h0-0-533" id="h0-0-533" class="i">+ web.form.Textbox('priority', web.form.notnull, web.form.regexp('\d+', 'number dumbass!'), description="Priority (high value more priority)"), 563 </a><a href="#h0-0-534" id="h0-0-534" class="i">+ web.form.Button('Save')) 564 </a><a href="#h0-0-535" id="h0-0-535" class="i">+ def GET(self, idvalue): 565 </a><a href="#h0-0-536" id="h0-0-536" class="i">+ if logged(): 566 </a><a href="#h0-0-537" id="h0-0-537" class="i">+ i = web.input() 567 </a><a href="#h0-0-538" id="h0-0-538" class="i">+ if i: 568 </a><a href="#h0-0-539" id="h0-0-539" class="i">+ if i.cmd == 'del': 569 </a><a href="#h0-0-540" id="h0-0-540" class="i">+ db.delete('products', where='id=' + idvalue) 570 </a><a href="#h0-0-541" id="h0-0-541" class="i">+ imgdir = staticdir + 'img/' + idvalue 571 </a><a href="#h0-0-542" id="h0-0-542" class="i">+ try: 572 </a><a href="#h0-0-543" id="h0-0-543" class="i">+ shutil.rmtree(imgdir,ignore_errors=True,onerror=None) 573 </a><a href="#h0-0-544" id="h0-0-544" class="i">+ except: 574 </a><a href="#h0-0-545" id="h0-0-545" class="i">+ print('no picture folder, nothing to remove...') 575 </a><a href="#h0-0-546" id="h0-0-546" class="i">+ pass 576 </a><a href="#h0-0-547" id="h0-0-547" class="i">+ raise web.seeother('/products/') 577 </a><a href="#h0-0-548" id="h0-0-548" class="i">+ if i.cmd == 'removeimg': 578 </a><a href="#h0-0-549" id="h0-0-549" class="i">+ os.remove(staticdir + '/img/' + idvalue + '/' + i.img) 579 </a><a href="#h0-0-550" id="h0-0-550" class="i">+ os.remove(staticdir + '/img/' + idvalue + '/web/' + i.img) 580 </a><a href="#h0-0-551" id="h0-0-551" class="i">+ os.remove(staticdir + '/img/' + idvalue + '/thumb/' + i.img) 581 </a><a href="#h0-0-552" id="h0-0-552" class="i">+ raise web.seeother('/products/' + idvalue) 582 </a><a href="#h0-0-553" id="h0-0-553" class="i">+ organizepics(idvalue) 583 </a><a href="#h0-0-554" id="h0-0-554" class="i">+ addproduct = self.form() 584 </a><a href="#h0-0-555" id="h0-0-555" class="i">+ addproduct.fill(available='1', priority='1') 585 </a><a href="#h0-0-556" id="h0-0-556" class="i">+ if idvalue: 586 </a><a href="#h0-0-557" id="h0-0-557" class="i">+ oldinfo = db.select('products', where="id=" + idvalue, what='name, description, price, available, priority, category') 587 </a><a href="#h0-0-558" id="h0-0-558" class="i">+ oldinfo = oldinfo[0] 588 </a><a href="#h0-0-559" id="h0-0-559" class="i">+ addproduct.fill(name=oldinfo.name, description=oldinfo.description, price=oldinfo.price, available=oldinfo.available, priority=oldinfo.priority, category=oldinfo.category) 589 </a><a href="#h0-0-560" id="h0-0-560" class="i">+ listproducts = db.query("SELECT * FROM products ORDER BY priority DESC") 590 </a><a href="#h0-0-561" id="h0-0-561" class="i">+ imgdir = staticdir + 'img/' + idvalue + '/web/' 591 </a><a href="#h0-0-562" id="h0-0-562" class="i">+ try: 592 </a><a href="#h0-0-563" id="h0-0-563" class="i">+ productimages = sorted(os.listdir(imgdir)) 593 </a><a href="#h0-0-564" id="h0-0-564" class="i">+ print(productimages) 594 </a><a href="#h0-0-565" id="h0-0-565" class="i">+ except: 595 </a><a href="#h0-0-566" id="h0-0-566" class="i">+ productimages = [] 596 </a><a href="#h0-0-567" id="h0-0-567" class="i">+ print('No productimages for this product') 597 </a><a href="#h0-0-568" id="h0-0-568" class="i">+ return renderop.products(addproduct, listproducts, productimages, idvalue) 598 </a><a href="#h0-0-569" id="h0-0-569" class="i">+ else: 599 </a><a href="#h0-0-570" id="h0-0-570" class="i">+ raise web.seeother('/login') 600 </a><a href="#h0-0-571" id="h0-0-571" class="i">+ def POST(self, idvalue): 601 </a><a href="#h0-0-572" id="h0-0-572" class="i">+ listproducts = db.query("SELECT * FROM products ORDER BY priority DESC") 602 </a><a href="#h0-0-573" id="h0-0-573" class="i">+ addproduct = self.form() 603 </a><a href="#h0-0-574" id="h0-0-574" class="i">+ if logged(): 604 </a><a href="#h0-0-575" id="h0-0-575" class="i">+ i = web.input(imgfile={}) 605 </a><a href="#h0-0-576" id="h0-0-576" class="i">+ for p in i: 606 </a><a href="#h0-0-577" id="h0-0-577" class="i">+ print(p) 607 </a><a href="#h0-0-578" id="h0-0-578" class="i">+ if i.imgfile != {}: 608 </a><a href="#h0-0-579" id="h0-0-579" class="i">+ if idvalue == '': 609 </a><a href="#h0-0-580" id="h0-0-580" class="i">+ print('cant upload a picture to a non existing product') 610 </a><a href="#h0-0-581" id="h0-0-581" class="i">+ raise web.seeother('/products/') 611 </a><a href="#h0-0-582" id="h0-0-582" class="i">+ print(i.imgfile.filename) 612 </a><a href="#h0-0-583" id="h0-0-583" class="i">+ if i.imgfile.filename == '': 613 </a><a href="#h0-0-584" id="h0-0-584" class="i">+ print('hmmm... no image to upload') 614 </a><a href="#h0-0-585" id="h0-0-585" class="i">+ raise web.seeother('/products/' + idvalue) 615 </a><a href="#h0-0-586" id="h0-0-586" class="i">+ print('YEAH, Upload image!') 616 </a><a href="#h0-0-587" id="h0-0-587" class="i">+ 617 </a><a href="#h0-0-588" id="h0-0-588" class="i">+ ##---------- UPLOAD IMAGE ---------- 618 </a><a href="#h0-0-589" id="h0-0-589" class="i">+ 619 </a><a href="#h0-0-590" id="h0-0-590" class="i">+ imgdir = staticdir + 'img/' + idvalue 620 </a><a href="#h0-0-591" id="h0-0-591" class="i">+ os.makedirs(imgdir, exist_ok=True) 621 </a><a href="#h0-0-592" id="h0-0-592" class="i">+ imgpath=i.imgfile.filename.replace('\\','/') # replaces the windows-style slashes with linux ones. 622 </a><a href="#h0-0-593" id="h0-0-593" class="i">+ #filename=filepath.split('/')[-1] # splits the and chooses the last part (the filename with extension) 623 </a><a href="#h0-0-594" id="h0-0-594" class="i">+ #filename = hashlib.md5(str(random.getrandbits(256)).encode('utf-8')).hexdigest() + '.jpeg' 624 </a><a href="#h0-0-595" id="h0-0-595" class="i">+ imgname = str(len(os.listdir(imgdir))).zfill(3) + '.jpeg' 625 </a><a href="#h0-0-596" id="h0-0-596" class="i">+ fout = open(imgdir +'/'+ imgname,'wb') # creates the file where the uploaded file should be stored 626 </a><a href="#h0-0-597" id="h0-0-597" class="i">+ fout.write(i.imgfile.file.read()) # writes the uploaded file to the newly created file. 627 </a><a href="#h0-0-598" id="h0-0-598" class="i">+ fout.close() # closes the file, upload complete. 628 </a><a href="#h0-0-599" id="h0-0-599" class="i">+ 629 </a><a href="#h0-0-600" id="h0-0-600" class="i">+ ##---------- OPEN FILE & CHEKC IF JPEG -------- 630 </a><a href="#h0-0-601" id="h0-0-601" class="i">+ 631 </a><a href="#h0-0-602" id="h0-0-602" class="i">+ image = Image.open(imgdir +'/'+ imgname) 632 </a><a href="#h0-0-603" id="h0-0-603" class="i">+ if image.format != 'JPEG': 633 </a><a href="#h0-0-604" id="h0-0-604" class="i">+ os.remove(imgdir +'/'+ imgname) 634 </a><a href="#h0-0-605" id="h0-0-605" class="i">+ raise web.seeother('/products/' + idvalue) 635 </a><a href="#h0-0-606" id="h0-0-606" class="i">+ 636 </a><a href="#h0-0-607" id="h0-0-607" class="i">+ ##---------- RESIZE IMAGE ----------- 637 </a><a href="#h0-0-608" id="h0-0-608" class="i">+ try: 638 </a><a href="#h0-0-609" id="h0-0-609" class="i">+ os.makedirs(imgdir + '/web/', exist_ok=True) 639 </a><a href="#h0-0-610" id="h0-0-610" class="i">+ os.makedirs(imgdir + '/thumb/', exist_ok=True) 640 </a><a href="#h0-0-611" id="h0-0-611" class="i">+ except: 641 </a><a href="#h0-0-612" id="h0-0-612" class="i">+ print('Folders is') 642 </a><a href="#h0-0-613" id="h0-0-613" class="i">+ image.thumbnail((900,900), Image.ANTIALIAS) 643 </a><a href="#h0-0-614" id="h0-0-614" class="i">+ image.save(imgdir + '/web/' + imgname) 644 </a><a href="#h0-0-615" id="h0-0-615" class="i">+ image.thumbnail((300,300), Image.ANTIALIAS) 645 </a><a href="#h0-0-616" id="h0-0-616" class="i">+ image.save(imgdir + '/thumb/' + imgname) 646 </a><a href="#h0-0-617" id="h0-0-617" class="i">+ 647 </a><a href="#h0-0-618" id="h0-0-618" class="i">+ organizepics(idvalue) 648 </a><a href="#h0-0-619" id="h0-0-619" class="i">+ raise web.seeother('/products/' + idvalue) 649 </a><a href="#h0-0-620" id="h0-0-620" class="i">+ if not addproduct.validates(): 650 </a><a href="#h0-0-621" id="h0-0-621" class="i">+ raise web.seeother('/products/' + idvalue) 651 </a><a href="#h0-0-622" id="h0-0-622" class="i">+ else: 652 </a><a href="#h0-0-623" id="h0-0-623" class="i">+ if idvalue: 653 </a><a href="#h0-0-624" id="h0-0-624" class="i">+ db.update('products', where='id=' + idvalue, category=i.category, name=i.name, description=i.description, price=i.price, available=i.available, sold=0, priority=i.priority, dateadded=datetime.datetime.now()) 654 </a><a href="#h0-0-625" id="h0-0-625" class="i">+ else: 655 </a><a href="#h0-0-626" id="h0-0-626" class="i">+ db.insert('products', category=i.category, name=i.name, description=i.description, price=i.price, available=i.available, sold=0, priority=i.priority, dateadded=datetime.datetime.now()) 656 </a><a href="#h0-0-627" id="h0-0-627" class="i">+ raise web.seeother('/products/' + idvalue) 657 </a><a href="#h0-0-628" id="h0-0-628" class="i">+ else: 658 </a><a href="#h0-0-629" id="h0-0-629" class="i">+ raise web.seeother('/login') 659 </a><a href="#h0-0-630" id="h0-0-630" class="i">+ 660 </a><a href="#h0-0-631" id="h0-0-631" class="i">+class shipping: 661 </a><a href="#h0-0-632" id="h0-0-632" class="i">+ form = web.form.Form( 662 </a><a href="#h0-0-633" id="h0-0-633" class="i">+ web.form.Textbox('country', web.form.notnull, description="Country:"), 663 </a><a href="#h0-0-634" id="h0-0-634" class="i">+ web.form.Textbox('price', web.form.regexp('\d+', 'number thanx!'), web.form.notnull, description="Price in cents"), 664 </a><a href="#h0-0-635" id="h0-0-635" class="i">+ web.form.Textbox('days', web.form.regexp('\d+', 'number thanx!'), web.form.notnull, description="Shipping in days"), 665 </a><a href="#h0-0-636" id="h0-0-636" class="i">+ web.form.Button('Add shipping country')) 666 </a><a href="#h0-0-637" id="h0-0-637" class="i">+ def GET(self, idvalue): 667 </a><a href="#h0-0-638" id="h0-0-638" class="i">+ if logged(): 668 </a><a href="#h0-0-639" id="h0-0-639" class="i">+ addcountry = self.form() 669 </a><a href="#h0-0-640" id="h0-0-640" class="i">+ if idvalue: 670 </a><a href="#h0-0-641" id="h0-0-641" class="i">+ oldinfo = db.select('shipping', where="id=" + idvalue, what='country, price, days') 671 </a><a href="#h0-0-642" id="h0-0-642" class="i">+ oldinfo = oldinfo[0] 672 </a><a href="#h0-0-643" id="h0-0-643" class="i">+ addcountry.fill(country=oldinfo.country, price=oldinfo.price, days=oldinfo.days) 673 </a><a href="#h0-0-644" id="h0-0-644" class="i">+ listcountries = db.query("SELECT * FROM shipping ORDER BY country DESC") 674 </a><a href="#h0-0-645" id="h0-0-645" class="i">+ return renderop.shipping(addcountry, listcountries) 675 </a><a href="#h0-0-646" id="h0-0-646" class="i">+ else: 676 </a><a href="#h0-0-647" id="h0-0-647" class="i">+ raise web.seeother('/login') 677 </a><a href="#h0-0-648" id="h0-0-648" class="i">+ def POST(self, idvalue): 678 </a><a href="#h0-0-649" id="h0-0-649" class="i">+ if logged(): 679 </a><a href="#h0-0-650" id="h0-0-650" class="i">+ addcountry = self.form() 680 </a><a href="#h0-0-651" id="h0-0-651" class="i">+ if not addcountry.validates(): 681 </a><a href="#h0-0-652" id="h0-0-652" class="i">+ listcountries = db.query("SELECT * FROM shipping ORDER BY country DESC") 682 </a><a href="#h0-0-653" id="h0-0-653" class="i">+ return renderop.shipping(addcountry, listcountries) 683 </a><a href="#h0-0-654" id="h0-0-654" class="i">+ else: 684 </a><a href="#h0-0-655" id="h0-0-655" class="i">+ i = web.input() 685 </a><a href="#h0-0-656" id="h0-0-656" class="i">+ if idvalue: 686 </a><a href="#h0-0-657" id="h0-0-657" class="i">+ db.update('shipping', where='id=' + idvalue, country=i.country, price=i.price, days=i.days) 687 </a><a href="#h0-0-658" id="h0-0-658" class="i">+ else: 688 </a><a href="#h0-0-659" id="h0-0-659" class="i">+ db.insert('shipping', country=i.country, price=i.price, days=i.days) 689 </a><a href="#h0-0-660" id="h0-0-660" class="i">+ raise web.seeother('/shipping/') 690 </a><a href="#h0-0-661" id="h0-0-661" class="i">+ else: 691 </a><a href="#h0-0-662" id="h0-0-662" class="i">+ raise web.seeother('/login') 692 </a><a href="#h0-0-663" id="h0-0-663" class="i">+ 693 </a><a href="#h0-0-664" id="h0-0-664" class="i">+class bitcoin: 694 </a><a href="#h0-0-665" id="h0-0-665" class="i">+ def GET(self): 695 </a><a href="#h0-0-666" id="h0-0-666" class="i">+ if logged(): 696 </a><a href="#h0-0-667" id="h0-0-667" class="i">+ bitcoinrpc = AuthServiceProxy(rpcauth) 697 </a><a href="#h0-0-668" id="h0-0-668" class="i">+ wallet = bitcoinrpc.getwalletinfo() 698 </a><a href="#h0-0-669" id="h0-0-669" class="i">+ bitcoinrpc = None 699 </a><a href="#h0-0-670" id="h0-0-670" class="i">+ return renderop.bitcoin(wallet) 700 </a><a href="#h0-0-671" id="h0-0-671" class="i">+ 701 </a><a href="#h0-0-672" id="h0-0-672" class="i">+application = app.wsgifunc() 702 </a></pre> 703 </div> 704 </body> 705 </html>