heartranked

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

commit be76dfe76555ab3538c198c1d9b20af1b249527d
parent 8b175cd3894302235eaae9dd8da7d175d26a7e11
Author: rbckman <rob@tarina.org>
Date:   Tue,  4 Aug 2026 23:52:44 +0300

ok ok ok

Diffstat:
Mhtml/heartranked.html | 148++++++++++++++++++++++++++++++++++++++-----------------------------------------
Mserver.py | 45++++++++++++++++++++++++++++++---------------
2 files changed, 102 insertions(+), 91 deletions(-)

diff --git a/html/heartranked.html b/html/heartranked.html @@ -117,84 +117,80 @@ $else: $:markdown.markdown('#welcome to HEART RANKED!') $else: $#goodies = db.select('published', where="postid='"+show+"'") - $#goodies=loadjson('p/posts/'+show+'/meta') - $ goodies=getfeed() - if goodies != []: - $for g in goodies: - <a href="/#$g['soundname']">back</a> - $if namn == g['creator']: - or <a href="/?edit=$g['postid']">edit</a> - $if namn: - or <a href="/editor?remix=$g['postid']">remix</a> - or <a href="/editor?combine=$g['postid']">combo</a> - $if namn == g['creator']: - or <small><a href="/?remove=$g['postid']">remove</a></small> - <div class="post" id="$g['soundname']"> - <br> - <div class="heartpost"> - $:markdown.markdown(loadtext('p/posts/'+g['postid']+'/intro')) - $:markdown.markdown(loadtext('p/posts/'+g['postid']+'/post')) - </div> - <div class="postmenu"> - <small>by $g['creator'] $g['timeadded']</small><br> - $getcombines(g['postid']) - $if 'combine' in g: - $#combined = db.select('published', where="postid='"+g['combine']+"'")[0] - $ combined=loadjson('p/posts/'+g['combine']+'/meta') - <small>combo with <a href="/?show=$combined['postid']">$combined['soundname']</a></small><br> - $if 'remix' in g: - $#remixed = db.select('published', where="postid='"+g['remix']+"'")[0] - $ remixed=loadjson('p/posts/'+g['remix']+'/meta') - <small>remixed <a href="/?show=$remixed['postid']">$remixed['soundname']</a></small><br> - or <a href="/#$g['soundname']">back</a> - $if namn == g['creator']: - or <a href="/?edit=$g['postid']">edit</a> - $if namn: - or <a href="/editor?remix=$g['postid']">remix</a> - or <a href="/editor?combine=$g['postid']">combo</a> - <div class="megalike" id="megalike$g['postid']" onclick="like('$g['postid']')">$getlikes(g['postid'],namn)</div> - <br> - </div> - </div> + $ g=loadjson('p/posts/'+show+'/meta') + $if g != {}: + <a href="/#$g['soundname']">back</a> + $if namn == g['creator']: + or <a href="/?edit=$g['postid']">edit</a> + $if namn: + or <a href="/editor?remix=$g['postid']">remix</a> + or <a href="/editor?combine=$g['postid']">combo</a> + $if namn == g['creator']: + or <small><a href="/?remove=$g['postid']">remove</a></small> + <div class="post" id="$g['soundname']"> + <br> + <div class="heartpost"> + $:markdown.markdown(loadtext('p/posts/'+g['postid']+'/intro')) + $:markdown.markdown(loadtext('p/posts/'+g['postid']+'/post')) + </div> + <div class="postmenu"> + <small>by $g['creator'] $g['timeadded']</small><br> + $getcombines(g['postid']) + $if 'combine' in g and g['combine'] != None: + $#combined = db.select('published', where="postid='"+g['combine']+"'")[0] + $ combined=loadjson('p/posts/'+g['combine']+'/meta') + <small>combo with <a href="/?show=$combined['postid']">$combined['soundname']</a></small><br> + $if 'remix' in g and g['remix'] != None: + $#remixed = db.select('published', where="postid='"+g['remix']+"'")[0] + $ remixed=loadjson('p/posts/'+g['remix']+'/meta') + <small>remixed <a href="/?show=$remixed['postid']">$remixed['soundname']</a></small><br> + or <a href="/#$g['soundname']">back</a> + $if namn == g['creator']: + or <a href="/?edit=$g['postid']">edit</a> + $if namn: + or <a href="/editor?remix=$g['postid']">remix</a> + or <a href="/editor?combine=$g['postid']">combo</a> + <div class="megalike" id="megalike$g['postid']" onclick="like('$g['postid']')">$getlikes(g['postid'],namn)</div> <br> + </div> + </div> + <br> + <br> + $ comboposts=getcombofeed(show) + $ choose_feed = False + $for c in comboposts: + $if c['soundname'] and choose_feed == False: + $#<small><a href="/?show=$g['postid']&feedbase=timebased">timebased 🌍</a> <a href="/?show=$g['postid']&feedbase=heart1day">heartbased ❤️ day</a> <a href="/?show=$g['postid']&feedbase=heart1week">week</a> <a href="/?show=$g['postid']&feedbase=heart1month">month</a> <a href="/?show=$g['postid']&feedbase=heart1year">year</a> <a href="/?show=$g['postid']&feedbase=alltime">alltime</a></small> + <small>🌍 <a href="/?show=$g['postid']&feedbase=time">time</a> ❤️ <a href="/?show=$g['postid']&feedbase=heart">heart</a> ⚭ <a href="/?show=$g['postid']&feedbase=combo">combo</a> for <a href="/?show=$g['postid']&feedbase=today">day</a> <a href="/?show=$g['postid']&timebase=week">week</a> <a href="/?show=$g['postid']&timebase=month">month</a> <a href="/?show=$g['postid']&timebase=year">year</a> <a href="/?show=$g['postid']&timebase=all">all</a></small> + $ choose_feed = True + <div class="post" id="$c['soundname']"> <br> - $ comboposts=getcombofeed(show) - $ choose_feed = False - $for c in comboposts: - $if c['soundname'] and choose_feed == False: - $#<small><a href="/?show=$g['postid']&feedbase=timebased">timebased 🌍</a> <a href="/?show=$g['postid']&feedbase=heart1day">heartbased ❤️ day</a> <a href="/?show=$g['postid']&feedbase=heart1week">week</a> <a href="/?show=$g['postid']&feedbase=heart1month">month</a> <a href="/?show=$g['postid']&feedbase=heart1year">year</a> <a href="/?show=$g['postid']&feedbase=alltime">alltime</a></small> - <small>🌍 <a href="/?show=$g['postid']&feedbase=time">time</a> ❤️ <a href="/?show=$g['postid']&feedbase=heart">heart</a> ⚭ <a href="/?show=$g['postid']&feedbase=combo">combo</a> for <a href="/?show=$g['postid']&feedbase=today">day</a> <a href="/?show=$g['postid']&timebase=week">week</a> <a href="/?show=$g['postid']&timebase=month">month</a> <a href="/?show=$g['postid']&timebase=year">year</a> <a href="/?show=$g['postid']&timebase=all">all</a></small> - $ choose_feed = True - <div class="post" id="$c['soundname']"> - <br> - <br> - <div class="heartpost"> - $:markdown.markdown(loadtext('p/posts/'+c['postid']+'/intro')) - $:markdown.markdown(loadtext('p/posts/'+c['postid']+'/post')) - </div> - <div class="postmenu"> - <small>by $c['creator'] $c['timeadded']</small><br> - $getcombines(c['postid']) - $if c['combine']: - $#combined = db.select('published', where="postid='"+c['combine']+"'")[0] - $ combined=loadjson('p/posts/'+c['combine']+'/meta') - <small>combo with <a href="/?show=$combined['postid']">$combined['soundname']</a></small><br> - $if c['remix']: - $#remixed = db.select('published', where="postid='"+c['remix']+"'")[0] - $ remixed=loadjson('p/posts/'+c['remix']+'/meta') - <small>remixed <a href="/?show=$remixed['postid']">$remixed['soundname']</a></small><br> - <a href="/?show=$c['postid']">more</a> - or <a href="/#$c['soundname']">back</a> - $if namn == c['creator']: - or <a href="/?edit=$c['postid']">edit</a> - $if namn: - or <a href="/editor?combine=$c['postid']">combo</a> - <div class="megalike" id="megalike$c['postid']" onclick="like('$c['postid']')">$getlikes(c['postid'],namn)</div> - <br> - </div> - </div> - else: - print('de nada') + <br> + <div class="heartpost"> + $:markdown.markdown(loadtext('p/posts/'+c['postid']+'/intro')) + $:markdown.markdown(loadtext('p/posts/'+c['postid']+'/post')) + </div> + <div class="postmenu"> + <small>by $c['creator'] $c['timeadded']</small><br> + $getcombines(c['postid']) + $if c['combine']: + $#combined = db.select('published', where="postid='"+c['combine']+"'")[0] + $ combined=loadjson('p/posts/'+c['combine']+'/meta') + <small>combo with <a href="/?show=$combined['postid']">$combined['soundname']</a></small><br> + $if c['remix']: + $#remixed = db.select('published', where="postid='"+c['remix']+"'")[0] + $ remixed=loadjson('p/posts/'+c['remix']+'/meta') + <small>remixed <a href="/?show=$remixed['postid']">$remixed['soundname']</a></small><br> + <a href="/?show=$c['postid']">more</a> + or <a href="/#$c['soundname']">back</a> + $if namn == c['creator']: + or <a href="/?edit=$c['postid']">edit</a> + $if namn: + or <a href="/editor?combine=$c['postid']">combo</a> + <div class="megalike" id="megalike$c['postid']" onclick="like('$c['postid']')">$getlikes(c['postid'],namn)</div> + <br> + </div> + </div> <br> <br> diff --git a/server.py b/server.py @@ -12,11 +12,7 @@ import subprocess import web import hashlib import random -import time -import shutil import settings -import binascii -import base64 import markdown import re import bcrypt @@ -123,11 +119,16 @@ def savejson(thename, thedict): json.dump(thedict,f) def loadjson(thename): - with open(basedir+thename, 'r') as f: - settings = json.load(f) - #for key, i in settings.items(): - # createpost(key,i) - return settings + if os.path.exists(basedir+thename): + with open(basedir+thename, 'r') as f: + settings = json.load(f) + #for key, i in settings.items(): + # createpost(key,i) + print(settings) + if settings != None: + return settings + else: + return '' def deletepost(thefile): os.system('rm '+thefile) @@ -379,11 +380,16 @@ class welcome(): class like: def POST(self): if session.user != '': - i = web.input(unlike=None, like=None, hate=None, unhate=None, user=None, postid=None) + i = web.input(unlike=None, like=None, hate=None, unhate=None, user=None, imghash=None) user = i.user - postid = i.postid + postid = i.imghash #l = db.query("SELECT * FROM likes WHERE bild='"+postid+"' AND user='"+session.user+"';") - l = loadjson('p/posts/'+postid+'/hearts/'+session.user) + os.makedirs(basedir+'p/posts/'+postid+'/hearts/',exist_ok=True) + os.makedirs(basedir+'u/'+session.user+'/posts/'+postid+'/hearts/',exist_ok=True) + try: + l = loadjson('p/posts/'+postid+'/hearts/'+session.user) + except: + l={} print(session.user) if l: user_likes = True @@ -391,14 +397,21 @@ class like: user_likes = False if user_likes == False: #db.insert('likes', user=session.user, bild=postid, datum=formattime(datetime.datetime.now())) - savedict={'timeadded':formattime(datetime.datetime.now())} + try: + l=len(os.listdir(basedir+'p/posts/'+postid+'/hearts/')) + except: + l=0 + #db.update('published', where='postid="'+postid+'"', hearts=l.likes) + thedict={'hearts':l} + savejson('p/posts/'+postid+'/meta',thedict) + savedict={'timeadded':formattime(datetime.datetime.now()),'siteurl':siteurl, 'hearts':l} savejson('p/posts/'+postid+'/hearts/'+session.user, savedict) - savejson('u/'+session.user+'/hearts/'+session.user, savedict) + savejson('u/'+session.user+'/posts/'+postid+'/hearts/'+session.user, savedict) user_likes = True elif user_likes == True: #db.query("DELETE FROM likes WHERE bild='"+postid+"' AND user='"+session.user+"';") deletepost(basedir+'p/posts/'+postid+'/hearts/'+session.user) - deletepost(basedir+'u/'+session.user+'/hearts/'+session.user) + deletepost(basedir+'u/'+session.user+'/posts/'+postid+'/hearts/'+session.user) user_likes = False #likes = db.query("SELECT Count(*) AS likes FROM likes WHERE bild='"+postid+"';")[0] likes = len(os.listdir(basedir+'p/posts/'+postid+'/hearts/')) @@ -838,6 +851,8 @@ def getlikes(postid, user): os.makedirs(basedir+'p/posts/'+postid+'/hearts/',exist_ok=True) try: l=len(os.listdir(basedir+'p/posts/'+postid+'/hearts/')) + print(os.listdir(basedir+'p/posts/'+postid+'/hearts/')) + print('fuuuuuukkk'+str(l)) except: l=0 #db.update('published', where='postid="'+postid+'"', hearts=l.likes)