from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
import random as ra
import asyncio
from . import mdl
import functools
def rerender(funky):
@functools.wraps(funky)
def wrap(req,*args,**kwargs):
with open('main/utils/navs') as b:
navs=parsecat(b,4)
namednavs=[{'id':blah[0], 'link':blah[1], 'text':blah[2], 'align':int(blah[3])} for blah in navs['']]
out=funky(*args,**kwargs)
temp=loader.get_template('main/nav.html')
out['nav']=temp.render({"navs":namednavs},None)
return render(req, 'main/temp.html', out)
return wrap
def parsecat(file,n):
if not isinstance(file,str):
# Assume open handle
stuff=file.read()
else:
with open(f'main/pages/{file}') as b:
stuff=b.read()
cats=stuff.split('\n\n')
out={}
head=''
out['']=[]
for cat in cats:
if ':' in cat[:cat.index('\n')]:
# We have a category name
head,cat=cat.split('\n',1)
head=head[:-1]
out[head]=[]
else: head=''
for line in cat.split('\n'):
lin=line.split(',',n-1)
pad=n-len(lin)
lin.extend(['']*pad)
out[head].append(lin)
if out['']==[]: del(out[''])
return out
@rerender
def index():
with open('main/pages/index') as b:
stuff=b.read()
with open('main/utils/song-ids') as b:
raws=b.read()
ids=raws.split('\n')
stuff=stuff.format(ra.choice(ids))
return {'title':'Home','content':stuff,'date':'2021/09/20'}
@rerender
def me():
with open('main/pages/quotes') as b:
stuff=b.read()
stuff={n[:n.index(': ')]:n[n.index(': ')+2:] for n in stuff.split('\n')}
lbn='\\n'
stuff='
\n'.join([f'"{v.replace(lbn,"
")}" - {k.replace(lbn,"
")}' for k,v in stuff.items()])
return {'title':'Me','content':stuff,'date':'2021/08/26'}
def lii(name,proto,link='',note=''):
if link: name=f"{name}"
if note: name=f"{name} ({note})"
return f"\n
Interesting/useful blog posts I've found.
" arts=parsecat('articles',2) out=[] for k,v in arts.items(): out.append(f''+('
'.join(out))+'
','date':'2021/05/06'} @rerender def todd(): out="""Obviously, this started as a joke and turned into a fully-fledged shitpost. The invite link is here, the culprit is Zergling_man#9849, and... It just spams, kinda. Every 10 minutes in every channel and once every time someone starts a message with a ., or mentions it. Don't forget to buy Skyrim. Try '.wake'!
Credits:Avatar cropped from this picture,
repeating text created by 'Jade', and kept sic.
Flashrim pictures provided by Emperor Tang.
Portalrim gif provided by ColeFreeman72.
Animated memes gif provided by SakoArorim.
Phonedrop gif provided by Takamatsu.
Mugrim also provided by Takamatsu.
Racerim provided by Kotz
"provided by" indicates the content was not created by the person. If no creator is mentioned, they're unknown.
As of 2021-04-14, I've taken this bot offline forever and released the token (and code). If you see it online, it's not my doing, and I don't care if it gets me banned.
""" return {'title':'It just works','content':out,'date':'2021/07/24'} def redirect(req,src): with open('main/pages/redirects') as b: lonks=b.read() lonks=dict([n.split(': ',1) for n in lonks.split('\n')]) return HttpResponse(status=302,headers={'Location':lonks[src]}) @rerender def bikebunny(): return {'title':'bikebunny','content':"I'm the rabbit-eared cyclist/bike bunny. And, well, the guy that wears blue bunny ears year-round (for now). This is my site. I live different, I encourage you to join me. Get in touch.",'date':'2021/07/24'} def md(req): loop=asyncio.get_event_loop() feed=loop.run_until_complete(mdl.makefeed(req.GET.getlist('ids',''))) return HttpResponse(feed, content_type='application/rss+xml') @rerender def todo(): return {'title':'Site TODOs','content':"Things to be done on the site: