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
  • {proto}: {name}
  • " @rerender def contact(): head="Certain people keep asking me about the best ways to contact me. So here they are, in rough order of most to least preferred. More to come as I remember them/feel like it
    " out=parsecat('contacts',4) out3='' for k,v in out.items(): out2=f"\n

    {k}

    \n

    " out3+=out2 return {'title':'Contact','content':head+out3,'date':'2021/08/13'} def specs(req): with open('main/pages/specs') as b: return HttpResponse(b.read(), content_type="text/plain") @rerender def songs(): with open('main/utils/song-ids') as b: raws=b.read() ids=raws.split('\n') out='This is the full list of songs that can appear on the home page.
    '+'
    \n'.join([f'https://invidious.ethibox.fr/watch?v={idd}' for idd in ids]) return {'title':'Songs','content':out,'date':'2021/05/06'} @rerender def host(): return {'title':'Webhost','content':"I want to do a fully-fledged hosting thing. Like offer an actual VPS. But that's a lot of effort, and I want to do things like \"you have a folder in your VPS that will show up on your custom subdomain\" and such. I have exactly zero idea how to make multiple subdomains point to a single computer though. So it turns out Apache actually just has a thing to do exactly that. But fuck Apache. nginx can do it too. TODO™",'date':'2021/05/06'} @rerender def free(): with open('main/pages/free') as b: return {'title':'Not free beer','content':b.read(),'date':'2021/07/24'} @rerender def myroids(): with open('main/pages/myroids') as b: return {'title':'#myroid:matrix.org','content':b.read(),'date':'2021/05/06'} @rerender def myroidbrowser(): with open('main/pages/myroidbrowse') as b: return {'title':'#myroid:matrix.org','content':b.read(),'date':'2021/05/15'} @rerender def nerdshope(): return {'title':'Nerds\' Hope','content':"Store stuff. TODO. Will include inventory and budget. FB
    Address is 21 Kensington St, Glenorchy
    Off dates 2021: 24th Sept, 29th Oct, 26th Nov
    Will be late on the 1st of Oct
    Not sure about 31st of Dec. Depends what other plans are made. I might host a NYE party that night.",'date':'2021/09/05'} @rerender def syntax(): return {'title':"What's that syntax?",'content':"

    What's that syntax?


    A far-future goal, this will be a service for looking up strange bits of syntax you see in programs, that you're trying to find the name for so that you can search for that.
    Inspired by other lookup services like What Anime is That?, and more importantly, by C#'s object initialiser.",'date':'2021/05/06'} def teapot(req): return HttpResponse("You're probably missing the joke.",status=418) @rerender def articles(): head="

    Interesting/useful blog posts I've found.

    " arts=parsecat('articles',2) out=[] for k,v in arts.items(): out.append(f'

    {k}

    '+ '
    '.join([f'{l[1] or l[0]}' for l in v])) return {'title':'Articles','content':'

    '+('

    '.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:
    ",'date':'2021/09/21'} @rerender def autopage(pageid): return {'title':'','content':'','date':''}