def blog_list(ea=''): if not ea: ea = api.echolist()[0] blogs = api.lst('et/%s' % ea) comms = mydict({n:len(api.lst('topic/%s' % n))-6 for n in blogs}) pge = request.query.page or '1' return template ('blog-list.html',ea=ea,blogs=blogs,comms=comms,pge=int(pge)-1)
def del_all(itm): if api.lst('topic/%s' % itm): del_from_tags(itm) for n in api.lst('topic/%s' % itm)[5:]: del_msg(n) unlist('topic.list', itm) touch('data/topic.list') os.remove('data/topic/%s' % itm) else: del_msg(itm)
def blog_tag(tag): blogs = api.lst('tags/%s' % hsh(tag)) comms = mydict({n: len(api.lst('topic/%s' % n)) - 6 for n in blogs}) msgs = mydict({n: api.get_msg(n) for n in blogs}) return template('blog-list.html', blogs=blogs, msgs=msgs, comms=comms, tag=tag, ea='', pge=-1, u=u())
def all_bundle(): response.content_type = 'text/plain; charset=utf-8' out = '' el, fl = {}, api.lst('e.list') for ea in fl: el[ea] = api.lst('e/%s' % ea) for n in [x.split()[0] for x in api.lst('m.accepted')]: for ea in fl: if n in el[ea]: out += '%s:%s\n' % (n,ea) break return out
def js_page(pge): response.content_type = 'application/javascript; charset=utf-8' if pge == 'lenta.js': mo = [api.get_msg(n.split()[0]) for n in reversed(api.lst('m.accepted'))] if request.query.lim: mo = mo[:int(request.query.lim)] return template('js.tpl',mo=mo,rq=request.query)
def echo_bundle(f): response.content_type = 'text/plain; charset=utf-8' out = [] for n in [x for x in f.split('/') if '.' in x]: out.append(n) out += [x for x in api.lst('e/%s' % n)] return '\n'.join(out)
def carbon_copy(carbon,uname): mo = [n for n in reversed(api.lst('carbon/%s' % carbon))] if carbon.startswith('_'): title = 'Сообщения от пользователя %s' % uname else: title = 'Сообщения для пользователя %s' % uname return template('echoarea.html',mo=mo,title=title,u=u(),desc='Карбонки',ea='',pge=0)
def lastcomm(ea,num,userdir=''): if ea: dl = api.lst('e/%s' % ea) else: dl = [n.split()[0] for n in api.lst('m.accepted')] if userdir: dl = [n for n in api.lst('carbon/%s' % userdir) if n in dl] cntr = 0 msgs = [] for n in reversed(dl): tmp = api.get_msg(n) if tmp.repto: msgs.append(tmp) cntr += 1 if cntr >= num: break return msgs
def carbon_area(di, un, ea=''): if di in ('from', 'to'): uh = hsh(un) if di == 'to' else '_' + hsh(un) comm = rss.lastcomm(ea, 20, uh) return template('reg/lastcomm.html', uname=un, comms=comm, u=u(), admikey=ak(), ea=ea) elif di == 'news': topic = api.lst('et/%s' % ea) if ea else api.lst('topic.list') um = set(api.lst('carbon/_' + hsh(un))) return template('reg/lastnews.html', uname=un, news=[x for x in topic if x in um][-15:], u=u(), ea=ea)
def gettop(ea, cnt=6): if ea: ealist = set(get_ea(ea)) topc = [] for n in os.listdir('data/nuser'): un = rf('data/nuser/%s' % n) l = len([x for x in lst('carbon/_%s' % n) if not ea or (x in ealist)]) if l: topc.append([l, un]) return list(reversed(sorted(topc)))[:cnt]
def unm(itm): out = api.lst('m.accepted') for n in out: mid, ts = n.split() if mid == itm: out.remove(n) if out: open('data/m.accepted', 'w').write('\n'.join(out) + '\n') else: open('data/m.accepted', 'w').write('') return True
def unlist(fn, itm): print fn, itm out = api.lst(fn) print out if itm in out: out.remove(itm) print out if out: open('data/' + fn, 'w').write('\n'.join(out) + '\n') else: os.remove('data/' + fn) return True
def start_page(): mo = [x.split()[0] for x in reversed(api.lst('m.accepted'))] return template('start.html',out=api.forums_list(),mo=mo,u=u())
def gen_blog(ea,num=30): topics = set(api.lst('topic.list')) comms = [x for x in api.get_ea(ea) if x in topics] return template('rss/rss.tpl',msgs=msglst(comms,num),title=ea,link='%s/blog/%s' % (conf.URL,ea),desc='%s: %s' % (ea,api.echo_desc(ea)))
def blog_topic(topicid): topic = api.lst('topic/%s' % topicid) mo = [api.get_msg(n) for n in topic[5:]] return template ('blog-topic.html',mo=mo)
def list_txt(): out = '' response.content_type = 'text/plain; charset=utf-8' for n in api.echolist(): out += '%s:%s:%s\n' % (n, len(api.lst('e/%s' % n)), api.echo_desc(n) or 'no desc') return out
def topic_list(topicid): topic = api.lst('topic/%s' % topicid) msgs = mydict({n:api.get_msg(n) for n in topic[5:]}) return template('forum-topic.html',topicid=topicid,topic=topic,msgs=msgs,u=u())
def print_topic(topicid): topic = api.lst('topic/%s' % topicid) return template('print.html', jd=api.get_msg(topic[5]), u=u())
def blog_select(): return template('select-blog.html', u=u(), ea='', out=[(n, len(api.lst('e/%s' % n)), api.echo_desc(n) or 'no desc') for n in api.echolist()])
def echo_list(ea): mo = [n for n in reversed(api.lst('e/%s' % ea))] pge = request.query.page or '1' return template('echoarea.html',mo=mo,title=ea,ea=ea,u=u(),desc=api.echo_desc(ea),pge=int(pge)-1)
def gen_topic(topicid,num=30): comms = api.lst('topic/%s' % topicid) ea, desc = comms[2], comms[1] return template('rss/rss.tpl',msgs=msglst(comms[6:],num),title=ea,link='%s/msg/%s' % (conf.URL,topicid),desc=desc)
def lenta_list(): mo = [n.split()[0] for n in reversed(api.lst('m.accepted'))] return template('echoarea.html',mo=mo,title='Лента сообщений',u=u(),ea='',desc='все сообщения всех эх',pge=0)