from django.http import HttpResponse
import random as ra
import asyncio
from . import mdl
from .models import Page,Contact,Update,Redirect
from rakka.utils import rerender,parsecat
@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':'2022/02/09'}
def lii(obj): # This will get moved to a template shortly
name=obj.name
if obj.url: name=f"{name}"
if obj.comment: name=f"{name} ({obj.comment})"
if obj.desktop: name=f"{name} 🖥"
if obj.mobile: name=f"{name} 📱"
return f"
{obj.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
🖥 = I will receive on my computer, 📱 = I will receive on my phone
"""
contacts=sorted(Contact.objects.all(),key=lambda x:(x.group,x.priority))
out={}
for n in contacts:
if n.group in out: out[n.group].append(n)
else: out[n.group]=[n]
out3=''
for k,v in out.items():
out2=f"\n{Contact.groups[k]}
\n"
out2+='\n'.join(map(lii,v))
out2+="\n
"
out3+=out2
return {'title':'Contact','content':head+out3,'date':Update.objects.get_or_create(page='contact')[0].date}
def specs(req):
with open('main/pages/specs') as b:
return HttpResponse(b.read(), content_type="text/plain")
@rerender
def comment():
return {'title':'Comment box','content':"TODO",'date':'2021/12/24'}
@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 nerdshope():
return {'title':"Nerds' Hope",'content':"Store stuff. TODO. Will include inventory and budget. FB
Address is 21 Kensington St, Glenorchy
Off dates 2022: 25th Feb, 4th March, 6th May, 17th June, 24th June",'date':'2022/02/09'}
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'}
def redirect(req,src):
return HttpResponse(status=302,headers={'Location':src.output})
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')
def vcard(req):
return HttpResponse("""BEGIN:VCARD
VERSION:4.0
KIND:individual
FN:Zergling_man
EMAIL:zerglingman@fedora.email
URL:https://rakka.tk
IMPP:xmpp:zergling_man@xmpp.jp;matrix:@zergling.man:perthchat.org
NOTE:Anti-professionalism, pro-open standards
CATEGORIES:programmer,biker
SOURCE:https://rakka.tk/me.vcf
END:VCARD""")
@rerender
def autopage(page):
return {'title':page.title,'content':page.contents,'date':page.last_edited}