#!/usr/bin/env python3
from georgedata import the
import urllib.request
import pathlib, datetime
p=pathlib.Path("/srv/web/george.gh0.pw/status.txt")
a=datetime.datetime.now().timestamp()-p.stat().st_mtime
if a > 300:
try:
st = urllib.request.urlopen("https://coral.shoes/george-status/george-status-html-but-epic").read().decode("utf-8")
except:
st = "a webring\x1e"
with open(p,"w") as f:
f.write(st)
else:
with open(p) as f:
st = f.read()
sts = st.split("\x1e")
with open("oldindex.html") as f:
index = f.read()
lt = '
{name}'
lt2 = '{name}'
def r(h):
import random
random.shuffle(h)
return h
s ="\n".join(r(list(lt.format(link=v[0],colour=v[1],name=k) for k,v in the.items())))
s2="\n".join(r(list( lt2.format(colour=v[1],name=k) for k,v in the.items() if len(v)>2 and v[2] )))
c='['+(', '.join(r(list(f'"{c}"' for c in (v[1] for v in the.values())))))+']'
print("Content-Type: text/html"); print()
print(index.replace("LINKS",s).replace("COLOURS",c).replace("COUNCIL",s2).replace("STATUS",sts[0]).replace("FOOTNOTE",sts[1]).replace("COUNT",str(len(the))))