Added easy to write articles
This commit is contained in:
parent
358049646c
commit
6571d498e4
5 changed files with 61 additions and 2 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
|
article.py
|
||||||
|
article.pyc
|
||||||
|
|
1
data/.htaccess
Normal file
1
data/.htaccess
Normal file
|
@ -0,0 +1 @@
|
||||||
|
deny from all
|
BIN
data/articles-0.pickle
Normal file
BIN
data/articles-0.pickle
Normal file
Binary file not shown.
8
index.py
8
index.py
|
@ -1,7 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from htmlgen import *
|
from htmlgen import *
|
||||||
|
import storage
|
||||||
print("Content-type: text/html\r\n\r\n")
|
print("Content-type: text/html\r\n\r\n")
|
||||||
html=htmlgen.HTMLgen(pagelayout.getLayoutXML().decode('utf-8'),"Home Page")
|
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("<!DOCTYPE html>")
|
||||||
|
print(html.renderSite())
|
||||||
html.addArticle("Markdown test","""*
|
html.addArticle("Markdown test","""*
|
||||||
* 1
|
* 1
|
||||||
* 2
|
* 2
|
||||||
|
@ -109,5 +115,3 @@ test
|
||||||
|
|
||||||
|
|
||||||
**TEST**""")
|
**TEST**""")
|
||||||
print("<!DOCTYPE html>")
|
|
||||||
print(html.renderSite())
|
|
||||||
|
|
52
storage.py
Normal file
52
storage.py
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
import pickle
|
||||||
|
import os
|
||||||
|
def get(name, num):
|
||||||
|
if not num < count (name):
|
||||||
|
raise IndexError
|
||||||
|
storagename="data/%s-%i.pickle"%(name,num/50)
|
||||||
|
f=open(storagename, "rb")
|
||||||
|
data=pickle.load(f)
|
||||||
|
f.close()
|
||||||
|
if not isinstance(data, list):
|
||||||
|
raise ValueError
|
||||||
|
return data[num%50]
|
||||||
|
|
||||||
|
def put(name, num, val):
|
||||||
|
if not num < count (name):
|
||||||
|
raise IndexError
|
||||||
|
storagename="data/%s-%i.pickle"%(name,num/50)
|
||||||
|
f=open(storagename, "rb")
|
||||||
|
data=pickle.load(f)
|
||||||
|
f.close()
|
||||||
|
if not isinstance(data, list):
|
||||||
|
raise ValueError
|
||||||
|
data[num%50]=val
|
||||||
|
f=open(storagename, "wb")
|
||||||
|
pickle.dump(data,f,-1)
|
||||||
|
f.close()
|
||||||
|
def append(name, val):
|
||||||
|
num=count(name)
|
||||||
|
storagename="data/%s-%i.pickle"%(name,num/50)
|
||||||
|
data=[]
|
||||||
|
try:
|
||||||
|
f=open(storagename, "rb")
|
||||||
|
data=pickle.load(f)
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
data.append(val)
|
||||||
|
f=open(storagename, "wb")
|
||||||
|
pickle.dump(data,f,-1)
|
||||||
|
f.close()
|
||||||
|
def count(name):
|
||||||
|
path = "data/"
|
||||||
|
files = [i for i in os.listdir(path) if os.path.isfile(os.path.join(path,i))
|
||||||
|
and name in i]
|
||||||
|
storagename="data/%s-%i.pickle"%(name,len(files)-1)
|
||||||
|
count=(len(files)-1)*50
|
||||||
|
if len(files) == 0:
|
||||||
|
return 0
|
||||||
|
f=open(storagename, "rb")
|
||||||
|
count = count + len(pickle.load(f))
|
||||||
|
f.close()
|
||||||
|
return count
|
Loading…
Reference in a new issue