anime.py!

This commit is contained in:
Morten Delenk 2016-06-14 18:07:17 +02:00
parent a22b92e77b
commit 5f1836ae2a
6 changed files with 37 additions and 7 deletions

2
.gitignore vendored
View file

@ -1,4 +1,2 @@
__pycache__/
*.pyc
article.py
article.pyc

16
anime.py Executable file
View file

@ -0,0 +1,16 @@
#!/usr/bin/env python3
from htmlgen import *
import storage
print("Content-type: text/html\r\n\r\n")
html=htmlgen.HTMLgen(pagelayout.getLayoutXML().decode('utf-8'),"Home Page")
count=storage.count("articles")
for i in range(count):
try:
article=storage.get("articles",i)
if "anime" in article["tags"]:
html.addArticle(**article)
except:
html.addArticle(**storage.get("articles",i), aid=i)
print("<!DOCTYPE html>")
print(html.renderSite())

9
article.py Executable file
View file

@ -0,0 +1,9 @@
#!/usr/bin/env python3
import storage, sys, time
name = input("Name: ")
title = input("Title: ")
tags = input("Tags: ").split(' ')
article = '\n'.join(sys.stdin.readlines())
timestamp = int(time.time())
data={"name":title,"markdown":article,"author":name,"date":timestamp, "tags":tags, "aid":storage.count("articles")}
storage.append("articles",data)

Binary file not shown.

View file

@ -10,13 +10,15 @@ class HTMLgen:
self.titles=[]
self.authors=[]
self.dates=[]
self.ids=[]
self.title=title
self.asideHTML=""
def addArticle(self, name, markdown, author="darklink", date=0):
def addArticle(self, name, markdown, author, date, aid, tags=None):
self.articles.append(markdown2.markdown(markdown, extras=["tables","spoiler"]))
self.titles.append(name)
self.authors.append(author)
self.dates.append(date)
self.ids.append(aid)
def prependHTML(self, text):
self.asideHTML=text+self.asideHTML
def appendHTML(self, text):
@ -25,14 +27,14 @@ class HTMLgen:
nav=""
x=len(self.titles)-1
for title in self.titles[::-1]:
nav=nav+("<a href=\"#%i\">%s</a><br/>" % (x, title))
nav=nav+("<a href=\"#%i\">%s</a><br/>" % (self.ids[x], title))
x=x-1
main=""
x=len(self.articles)-1
for article in self.articles[::-1]:
main=main+("<h2 id=\"%i\">%s</h2><p>Written on <time datetime=\"%s\">%s</time> by %s</p><article>%s</article>" %(x,self.titles[x],datetime.datetime.fromtimestamp(self.dates[x]).strftime("%Y-%m-%d %H:%M:%S"),datetime.datetime.fromtimestamp(self.dates[x]).strftime("%c"),self.authors[x],article))
main=main+("<h2 id=\"%i\">%s</h2><p>Written on <time datetime=\"%s\">%s</time> by %s</p><article>%s</article>" %(self.ids[x],self.titles[x],datetime.datetime.fromtimestamp(self.dates[x]).strftime("%Y-%m-%d %H:%M:%S"),datetime.datetime.fromtimestamp(self.dates[x]).strftime("%c"),self.authors[x],article))
if not comments:
main=main+("<a href=\"comments.py?aid=%i\">Comments (%i)</a>") % (x, storage.count("comments-%i"%x))
main=main+("<a href=\"comments.py?aid=%i\">Comments (%i)</a>") % (self.ids[x], storage.count("comments-%i"%self.ids[x]))
x=x-1
if not comments:
styleargs = {"title":self.title,"nav":nav,"main":main,"aside":self.asideHTML,"footer":"Copyright 2016 Morten"}

View file

@ -5,7 +5,12 @@ print("Content-type: text/html\r\n\r\n")
html=htmlgen.HTMLgen(pagelayout.getLayoutXML().decode('utf-8'),"Home Page")
count=storage.count("articles")
for i in range(count):
html.addArticle(**(storage.get("articles",i)))
try:
article=storage.get("articles",i)
if "homepage" in article["tags"]:
html.addArticle(**article)
except:
html.addArticle(**storage.get("articles",i), aid=i)
print("<!DOCTYPE html>")
print(html.renderSite())