diff --git a/articles-0.pickle b/articles-0.pickle
deleted file mode 100644
index 5a80d20..0000000
Binary files a/articles-0.pickle and /dev/null differ
diff --git a/comments.py b/comments.py
new file mode 100755
index 0000000..318030b
--- /dev/null
+++ b/comments.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+from htmlgen import *
+import storage
+import cgi
+import random
+import base64
+from io import BytesIO
+from captcha.image import ImageCaptcha
+import time
+print("Content-type: text/html\r\n\r\n")
+aid=form["aid"]
+form=cgi.FieldStorage()
+try:
+ seed=form["seed"]
+ random.seed(seed)
+ checkstr=list("".join(random.choice(string.digits+string.ascii_lowercase) for _ in range(5)))
+ if not checkstr == form["checkstr"]:
+ print("Captcha's wrong")
+ raise Exception()
+ username=form["username"]
+ message=form["message"]
+ timestamp=int(time.time())
+ data={"name":"","markdown":message,"author":username,"date":timestamp}
+ storage.append("comments-%i"%aid,data)
+except:
+ pass
+
+seed=random.SystemRandom().randint(0,2**24)
+random.seed(seed)
+checkstr=list("".join(random.choice(string.digits+string.ascii_lowercase) for _ in range(5)))
+image = ImageCaptcha()
+capt = image.generate(checkstr)
+html=htmlgen.HTMLgen(pagelayout.getLayoutXML().decode('utf-8'),"Comments")
+html.appendHTML("
"%seed)
+html.appendHTML("
")
+html.appendHTML("
")
+html.appendHTML("" % base64.b64encode(capt.getvalue()))
+html.appendHTML("")
+html.appendHTML("")
+count=storage.count("comments-%i"%aid)
+for i in range(count):
+ html.addArticle(**(storage.get("comments-%i"%aid,i)))
diff --git a/data/articles-0.pickle b/data/articles-0.pickle
index 22728b9..80de7e7 100644
Binary files a/data/articles-0.pickle and b/data/articles-0.pickle differ
diff --git a/data/articles-1.pickle b/data/articles-1.pickle
deleted file mode 100644
index fd00363..0000000
Binary files a/data/articles-1.pickle and /dev/null differ
diff --git a/data/articles-10.pickle b/data/articles-10.pickle
deleted file mode 100644
index e9b496b..0000000
Binary files a/data/articles-10.pickle and /dev/null differ
diff --git a/data/articles-11.pickle b/data/articles-11.pickle
deleted file mode 100644
index 048e94b..0000000
Binary files a/data/articles-11.pickle and /dev/null differ
diff --git a/data/articles-12.pickle b/data/articles-12.pickle
deleted file mode 100644
index 14bb170..0000000
Binary files a/data/articles-12.pickle and /dev/null differ
diff --git a/data/articles-13.pickle b/data/articles-13.pickle
deleted file mode 100644
index b6fe97b..0000000
Binary files a/data/articles-13.pickle and /dev/null differ
diff --git a/data/articles-14.pickle b/data/articles-14.pickle
deleted file mode 100644
index d90aba0..0000000
Binary files a/data/articles-14.pickle and /dev/null differ
diff --git a/data/articles-15.pickle b/data/articles-15.pickle
deleted file mode 100644
index dc2d261..0000000
Binary files a/data/articles-15.pickle and /dev/null differ
diff --git a/data/articles-16.pickle b/data/articles-16.pickle
deleted file mode 100644
index 3ab2222..0000000
Binary files a/data/articles-16.pickle and /dev/null differ
diff --git a/data/articles-17.pickle b/data/articles-17.pickle
deleted file mode 100644
index 3b0c249..0000000
Binary files a/data/articles-17.pickle and /dev/null differ
diff --git a/data/articles-18.pickle b/data/articles-18.pickle
deleted file mode 100644
index 584587b..0000000
Binary files a/data/articles-18.pickle and /dev/null differ
diff --git a/data/articles-19.pickle b/data/articles-19.pickle
deleted file mode 100644
index b26562d..0000000
Binary files a/data/articles-19.pickle and /dev/null differ
diff --git a/data/articles-2.pickle b/data/articles-2.pickle
deleted file mode 100644
index e109ab2..0000000
Binary files a/data/articles-2.pickle and /dev/null differ
diff --git a/data/articles-20.pickle b/data/articles-20.pickle
deleted file mode 100644
index 920b801..0000000
Binary files a/data/articles-20.pickle and /dev/null differ
diff --git a/data/articles-3.pickle b/data/articles-3.pickle
deleted file mode 100644
index 56d9bd4..0000000
Binary files a/data/articles-3.pickle and /dev/null differ
diff --git a/data/articles-4.pickle b/data/articles-4.pickle
deleted file mode 100644
index 6c6ad53..0000000
Binary files a/data/articles-4.pickle and /dev/null differ
diff --git a/data/articles-5.pickle b/data/articles-5.pickle
deleted file mode 100644
index f7d3971..0000000
Binary files a/data/articles-5.pickle and /dev/null differ
diff --git a/data/articles-6.pickle b/data/articles-6.pickle
deleted file mode 100644
index 358fdda..0000000
Binary files a/data/articles-6.pickle and /dev/null differ
diff --git a/data/articles-7.pickle b/data/articles-7.pickle
deleted file mode 100644
index 0e30b4b..0000000
Binary files a/data/articles-7.pickle and /dev/null differ
diff --git a/data/articles-8.pickle b/data/articles-8.pickle
deleted file mode 100644
index 57f145d..0000000
Binary files a/data/articles-8.pickle and /dev/null differ
diff --git a/data/articles-9.pickle b/data/articles-9.pickle
deleted file mode 100644
index f495a77..0000000
Binary files a/data/articles-9.pickle and /dev/null differ
diff --git a/htmlgen/htmlgen.py b/htmlgen/htmlgen.py
index d7ee4b5..6092419 100644
--- a/htmlgen/htmlgen.py
+++ b/htmlgen/htmlgen.py
@@ -1,6 +1,7 @@
import cgitb
import markdown2
import datetime
+import storage
cgitb.enable()
class HTMLgen:
def __init__(self, layout, title):
@@ -10,21 +11,27 @@ class HTMLgen:
self.authors=[]
self.dates=[]
self.title=title
+ self.asideHTML=""
def addArticle(self, name, markdown, author="darklink", date=0):
self.articles.append(markdown2.markdown(markdown, extras=["tables","spoiler"]))
self.titles.append(name)
self.authors.append(author)
self.dates.append(date)
+ def prependHTML(self, text):
+ self.asideHTML=text+self.asideHTML
+ def appendHTML(self, text):
+ self.asideHTML=self.asideHTML+text
def renderSite(self):
nav=""
- x=0
- for title in self.titles:
+ x=len(self.titles)-1
+ for title in self.titles[::-1]:
nav=nav+("%s
" % (x, title))
- x=x+1
+ x=x-1
main=""
- x=0
- for article in self.articles:
+ x=len(self.articles)-1
+ for article in self.articles[::-1]:
main=main+("%s
Written on by %s
%s" %(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))
- x=x+1
- styleargs = {"title":self.title,"nav":nav,"main":main,"aside":str(x),"footer":"Copyright 2016 Morten"}
+ main=main+("Comments (%i)") % (x, storage.count("comments-%i"%x))
+ x=x-1
+ styleargs = {"title":self.title,"nav":nav,"main":main,"aside":asideHTML,"footer":"Copyright 2016 Morten"}
return self.layout%styleargs
diff --git a/index.py b/index.py
index b0d6c17..9b1be82 100755
--- a/index.py
+++ b/index.py
@@ -6,112 +6,6 @@ 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)))
+
print("")
print(html.renderSite())
-html.addArticle("Markdown test","""*
-* 1
-* 2
-* 3
-
-# 1
-# 2
-# 3
-
-## half adder truth table
-
-| | 0 | 1 |
-|---|---|---|
-| 0 |0 0|0 1|
-| 1 |0 1|1 0|
-""")
-html.addArticle("Markdown test","""*Hello, World!*
-
-test
-test
-**HI**
-SPOILERS:
->! SPOILERED!
->! ロボボプラネットはいいぞ!
-
-""")
-html.addArticle("Markdown test","""*Hello, World!*
-
-test
-test
-**HI**
-
-
-
-**TEST**""")
-html.addArticle("Markdown test","""*Hello, World!*
-
-test
-test
-**HI**
-
-
-
-**TEST**""")
-html.addArticle("Markdown test","""*Hello, World!*
-
-test
-test
-**HI**
-
-
-
-**TEST**""")
-html.addArticle("Markdown test","""*Hello, World!*
-
-test
-test
-**HI**
-
-
-
-**TEST**""")
-html.addArticle("Markdown test","""*Hello, World!*
-
-test
-test
-**HI**
-
-
-
-**TEST**""")
-html.addArticle("Markdown test","""*Hello, World!*
-
-test
-test
-**HI**
-
-
-
-**TEST**""")
-html.addArticle("Markdown test","""*Hello, World!*
-
-test
-test
-**HI**
-
-
-
-**TEST**""")
-html.addArticle("Markdown test","""*Hello, World!*
-
-test
-test
-**HI**
-
-
-
-**TEST**""")
-html.addArticle("Markdown test","""*Hello, World!*
-
-test
-test
-**HI**
-
-
-
-**TEST**""")