commit 91a5830213716de83d78e9537e2f7b65c981a042
parent b09e535999537a60df9a46b7f1b12806f87b856b
Author: rob <rob@tarina.org>
Date: Thu, 20 Feb 2025 11:28:36 +0200
moreä
Diffstat:
4 files changed, 99 insertions(+), 38 deletions(-)
diff --git a/public_html/templates/almost.html b/public_html/templates/almost.html
@@ -1,11 +1,11 @@
-$def with (products,bag,sessionkey,productname,inbag,db,getprice,getrate,category,markdown)
+$def with (products,bag,sessionkey,productname,inbag,db,getprice,getrate,category,markdown,visitors, total, unique)
$ siteconfig = db.select('propaganda', what='id, name, description, description2')[0]
<HEAD>
<meta charset="utf-8">
<title>$siteconfig.name | $siteconfig.description</title>
- <link rel="stylesheet" href="/static/splash.css?v=100" type="text/css" rel="stylesheet"/>
+ <link rel="stylesheet" href="/static/splash.css?v=101" type="text/css" rel="stylesheet"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="cache-control" content="no-cache">
</HEAD>
@@ -39,8 +39,14 @@ $if sessionkey != 'empty':
<code>~</code>
</div>
</div>
-
-
+<div id="visitors">
+last visits by countries:
+$for i in visitors:
+ <img src="/static/flags/${i}.png">
+<br>
+unique visits since December 9 2024: $unique <br>
+<br>
+</div>
<div class="introtext">
<br>
<code>~*~</code>
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>Robin Bäckman | Inventor, filmmaker, gardener</title>
- <link rel="stylesheet" href="/static/robstyle.css?v=127" type="text/css" rel="stylesheet"/>
+ <link rel="stylesheet" href="/static/robstyle.css?v=168" 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
@@ -52,38 +52,39 @@ $for c in categories:
<div id="productlist">
$for i in products:
$if category == i.category or category == None:
- <div class="product" id="$i.id">
- <code>~*~</code>
- <h2>
- $i.name
- </h2>
- <code>$i.category</code>
- <br>
- <br>
- $ goodies = db.query("SELECT * FROM soundlink WHERE id='" +i.id+"';")
- $for g in goodies:
- $if g.soundname[-5:] == '.jpeg' or g.soundname[-4:] == '.png':
- <a href="/bigpic/$g.id"><img class="imgprod" src="/static/img/thumb/$g.soundname"></a>
- <br>
-
- <br>
- $code:
- sat, euro = getprice(i.id)
- $:markdown.markdown(i.description)
- product: $i.name
- <br>
- category: $i.category
- <br>
- <br>
$if i.available > 0:
- Price $sat Satoshi ~ $euro € <a href="/shop?putinbag=$i.id#$i.id">add to cart</a><br>
- Available $i.available pcs
- $else:
- SOLD OUT! check back later.
- </div>
- <br>
- <small>~-~</small>
- <br>
+ <div class="product" id="$i.id">
+ <code>~*~</code>
+ <h2>
+ $i.name
+ </h2>
+ <code>$i.category</code>
+ <br>
+ <br>
+ $ goodies = db.query("SELECT * FROM soundlink WHERE id='" +i.id+"';")
+ $for g in goodies:
+ $if g.soundname[-5:] == '.jpeg' or g.soundname[-4:] == '.png':
+ <a href="/bigpic/$g.id"><img class="imgprod" src="/static/img/thumb/$g.soundname"></a>
+ <br>
+
+ <br>
+ $code:
+ sat, euro = getprice(i.id)
+ $:markdown.markdown(i.description)
+ product: $i.name
+ <br>
+ category: $i.category
+ <br>
+ <br>
+ $if i.available > 0:
+ Price $sat Satoshi ~ $euro € <a href="/shop?putinbag=$i.id#$i.id">add to cart</a><br>
+ Available $i.available pcs
+ $else:
+ SOLD OUT! check back later.
+ </div>
+ <br>
+ <small>~-~</small>
+ <br>
</div>
<img class="logo" src="/static/bitcoin.png">
<br>
diff --git a/server.py b/server.py
@@ -29,6 +29,7 @@ urls = (
'/dropitem/(.*)?', 'dropitem',
'/payln/(.*)', 'payln',
'/goodies/(.*)', 'goodies',
+ "/stats", "stats",
'/lightning?', 'lightning',
'/paybtc/(.*)', 'paybtc',
'/payment/(.*)', 'payment',
@@ -154,15 +155,16 @@ def callsubprocess(cmd):
def dropitems(d):
i = getproduct(d)
- db.update('products', where="id='"+str(i.id)+"'", available=i.available+1)
try:
product = db.query("SELECT * FROM customerbag WHERE sessionkey='" + session.sessionkey +"' AND product='"+str(i.id)+"';")[0]
except:
return 'empty'
if product.quantity > 1:
db.update('customerbag', where="sessionkey='" + session.sessionkey +"' and product='"+str(i.id)+"'", quantity=product.quantity-1)
+ db.update('products', where="id='"+str(i.id)+"'", available=i.available+1)
else:
db.query("DELETE FROM customerbag WHERE sessionkey='" + session.sessionkey +"' AND product='"+str(i.id)+"';")
+ db.update('products', where="id='"+str(i.id)+"'", available=i.available+1)
return 'empty'
def addtobag(p):
@@ -310,6 +312,10 @@ def getpendinginfo():
class index():
def GET(self):
+ ip = web.ctx['ip']
+ referer = web.ctx.env.get('HTTP_REFERER', 'none')
+ environ = web.ctx.env.get('HTTP_USER_AGENT', 'dunno')
+ visitorlog(ip,referer,environ)
checkforoldbags()
i = web.input(dropitem=None, putinbag=None,error=None,prod=None,category=None)
if session.sessionkey == 'empty':
@@ -338,6 +344,11 @@ class index():
class almost():
def GET(self):
+ ip = web.ctx['ip']
+ referer = web.ctx.env.get('HTTP_REFERER', 'none')
+ environ = web.ctx.env.get('HTTP_USER_AGENT', 'dunno')
+ visitorlog(ip,referer,environ)
+ visitors, total, unique = getvisits()
checkforoldbags()
i = web.input(dropitem=None, putinbag=None,error=None,prod=None,category=None)
if session.sessionkey == 'empty':
@@ -362,8 +373,51 @@ class almost():
inbag = None
if inbag < 1:
session.sessionkey = 'empty'
- return rendersplash.almost(products,bag,session.sessionkey,productname,inbag,db,getprice,getrate,i.category, markdown)
+ return rendersplash.almost(products,bag,session.sessionkey,productname,inbag,db,getprice,getrate,i.category, markdown, visitors, total, unique)
+def visitorlog(ip, referer, environ):
+ last = db.query('SELECT ip AS ip FROM visitors WHERE id=(SELECT MAX(id) FROM visitors)')
+ try:
+ lastip = last[0].ip
+ except:
+ lastip = 'none'
+ if lastip != ip:
+ country = ''
+ country = os.popen('geoiplookup '+ip).read()
+ #print(soundtype)
+ countrycode = country.split(':')[1].split(',')[0].lower().strip()
+ country = country.split(':')[1].split(',')[1].strip()
+ #print('fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu: '+ country)
+ db.insert('visitors', ip=ip, referer=referer, environ=environ, country=country, countrycode=countrycode, time=datetime.datetime.now())
+ print("added to visitor log")
+ return
+
+def getvisitors():
+ visitors = db.select('visitors')
+ total = db.query('SELECT COUNT(*) AS total_visits FROM visitors')
+ unique = db.query('SELECT COUNT(DISTINCT ip) AS unique_visits FROM visitors')
+ return visitors, total[0].total_visits, unique[0].unique_visits
+
+def getvisits():
+ limit=100
+ visits = db.query("SELECT * FROM visitors ORDER BY time DESC LIMIT " + str(limit))
+ visitors = db.select('visitors')
+ total = db.query('SELECT COUNT(*) AS total_visits FROM visitors')
+ unique = db.query('SELECT COUNT(DISTINCT ip) AS unique_visits FROM visitors')
+ countrylist=[]
+ for i in visits:
+ if i.countrycode not in countrylist:
+ countrylist.append(i.countrycode)
+ #print('fuuuuuuuuuuuuuuu: '+i.countrycode)
+ return countrylist, total[0].total_visits, unique[0].unique_visits
+
+class stats:
+ def GET(self):
+ if logged():
+ visitors, total, unique = getvisitors()
+ return render.stats(visitors, total, unique)
+ else:
+ raise web.seeother('/login')
class putinbag:
def GET(self, p):