rakkapy/main/views.py

102 lines
5.2 KiB
Python
Raw Normal View History

2021-09-18 21:37:18 +10:00
from django.http import HttpResponse
import random as ra
import asyncio
from . import mdl
2022-02-27 23:23:26 +11:00
from .models import Page,Contact,Update,Redirect
2021-09-18 21:37:18 +10:00
from rakka.utils import rerender,parsecat
2021-09-18 21:37:18 +10:00
@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))
2022-02-10 06:02:55 +11:00
return {'title':'Home','content':stuff,'date':'2022/02/09'}
2021-09-18 21:37:18 +10:00
def lii(obj): # This will get moved to a template shortly
2021-12-12 21:52:02 +11:00
name=obj.name
2022-04-06 00:50:06 +10:00
relme="rel='me' " if obj.rel else ''
if obj.url: name=f"<a {relme}href='{obj.url}'>{name}</a>"
2021-12-12 21:52:02 +11:00
if obj.comment: name=f"{name} ({obj.comment})"
2021-12-24 12:01:00 +11:00
if obj.desktop: name=f"{name} 🖥"
if obj.mobile: name=f"{name} 📱"
2021-12-12 21:52:02 +11:00
return f"<li>{obj.proto}: {name}</li>"
2021-09-18 21:37:18 +10:00
@rerender
def contact():
2021-12-24 12:01:00 +11:00
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<br/>
🖥 = I will receive on my computer, 📱 = I will receive on my phone<br/>"""
2021-12-12 21:53:10 +11:00
contacts=sorted(Contact.objects.all(),key=lambda x:(x.group,x.priority))
2021-12-12 21:52:02 +11:00
out={}
for n in contacts:
if n.group in out: out[n.group].append(n)
else: out[n.group]=[n]
2021-09-18 21:37:18 +10:00
out3=''
for k,v in out.items():
2021-12-12 21:52:02 +11:00
out2=f"\n<p><h4>{Contact.groups[k]}</h4>\n<ul>"
out2+='\n'.join(map(lii,v))
2021-09-18 21:37:18 +10:00
out2+="\n</ul></p>"
out3+=out2
return {'title':'Contact','content':head+out3,'date':Update.objects.get_or_create(page='contact')[0].date}
2021-09-18 21:37:18 +10:00
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'}
2021-09-18 21:37:18 +10:00
@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.<br/>'+'<br/>\n'.join([f'<a href="https://invidious.ethibox.fr/watch?v={idd}">https://invidious.ethibox.fr/watch?v={idd}</a>' for idd in ids])
return {'title':'Songs','content':out,'date':'2021/05/06'}
def teapot(req):
return HttpResponse("You're probably missing the joke.",status=418)
@rerender
def articles():
head="<p>Interesting/useful blog posts I've found.</p>"
arts=parsecat('articles',2)
out=[]
for k,v in arts.items():
out.append(f'<h4>{k}</h4>\n'+ '<br/>\n'.join([f'<a href="{l[0]}">{l[1] or l[0]}</a>' for l in v]))
return {'title':'Articles','content':'<p>'+('</p>\n<p>'.join(out))+'</p>','date':'2022/04/11'}
2021-09-18 21:37:18 +10:00
def redirect(req,src):
2022-02-27 23:23:26 +11:00
return HttpResponse(status=302,headers={'Location':src.output})
2021-09-18 21:37:18 +10:00
@rerender
def mdhelp():
return {'title':'How2MD RSS','date':'2022/05/27','content':"This is an <a href='https://en.wikipedia.org/wiki/RSS'>RSS</a> service for <a href='https://mangadex.org'>Mangadex</a>, since they had one in v3 that I made liberal use of, and I've heard nothing regarding its return in v5.<br/>If you've never used RSS before, I strongly recommend starting, as it's the second-best update notification system in existence (and it could be built on #1, push notifications, but that's an another topic).<br/>You will need an RSS reader program, but your browser probably has one built in, so you can just use that. (I don't recommend it, because you should be closing the browser more, not less.)<br/>The important part of an RSS feed is a source URL. If properly configured, that should provide everything else. In this case, you've already found the source URL... Kinda. You need to pass a manga ID (or several) to make it work. A manga ID looks like this: ed996855-70de-449f-bba2-e8e24224c14d (yes, that's a UUID4). If you go to a manga's page on Mangadex, you should see something like it in the URL bar at the top. I think Tachiyomi has some way to grab it, but I also think Tachi's update notifs are better than mine, so if you have that you don't need this.<br/>Once you have the ID(s), you should palm them into this page like this: <a href='/md.rss?ids=ed996855-70de-449f-bba2-e8e24224c14d'>https://rakka.tk/md.rss?ids=ed996855-70de-449f-bba2-e8e24224c14d</a>. Take that and give it to your RSS reader as a new feed and it should handle the rest (did your browser ask you a new question when you clicked it?). If you want more IDs, put an & and do it again: <a href='/md.rss?ids=ed996855-70de-449f-bba2-e8e24224c14d&ids=/d032cdeb-1ced-4031-8b9e-45e6064c1781'>https://rakka.tk/md.rss?ids=ed996855-70de-449f-bba2-e8e24224c14d&ids=d032cdeb-1ced-4031-8b9e-45e6064c1781</a>.<br/>It behaves a bit differently with 1 ID vs multiple, but it should work alright both ways. Personally I prefer making one feed for each series."}
2021-09-18 21:37:18 +10:00
def md(req):
ids=req.GET.getlist('ids','')
if not ids: return mdhelp(req)
2021-09-18 21:37:18 +10:00
loop=asyncio.get_event_loop()
feed=loop.run_until_complete(mdl.makefeed(ids))
return HttpResponse(feed, content_type='application/rss+xml')
2021-11-10 02:45:32 +11:00
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""")
2021-12-10 03:33:05 +11:00
2021-10-09 20:36:50 +11:00
@rerender
2021-10-10 00:27:52 +11:00
def autopage(page):
return {'title':page.title,'content':page.contents,'date':page.last_edited}