|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
import datetime, os
|
|
|
|
|
import datetime, os, re
|
|
|
|
|
from bottle import error, route, run, static_file, template
|
|
|
|
|
|
|
|
|
|
# make article-to-html work with entries
|
|
|
|
|
# make index work with entries - later, they can be differentiated into features and weeklies with tags or title or whatever
|
|
|
|
|
|
|
|
|
|
# write diary
|
|
|
|
|
|
|
|
|
|
def build_nav():
|
|
|
|
@ -22,17 +25,22 @@ def list_snippets(articles):
|
|
|
|
|
result = []
|
|
|
|
|
|
|
|
|
|
for article in articles:
|
|
|
|
|
path = 'entries/' + article
|
|
|
|
|
text = []
|
|
|
|
|
a = []
|
|
|
|
|
length = 0
|
|
|
|
|
with open('entries/feature/' + article) as f:
|
|
|
|
|
with open('entries/' + article) as f:
|
|
|
|
|
text = f.readlines()
|
|
|
|
|
length = len(text)
|
|
|
|
|
a.append(text[head])
|
|
|
|
|
a.append(snip_article(find_content(article, length, head, tail)))
|
|
|
|
|
a.append(text[head + 1])
|
|
|
|
|
content = snip_article(find_content(article, length, head, tail), path)
|
|
|
|
|
|
|
|
|
|
if content.count('<ul>') > content.count('</ul>'):
|
|
|
|
|
content += '</ul>'
|
|
|
|
|
a.append(content)
|
|
|
|
|
a.append(text[head + 1].replace('<br>',''))
|
|
|
|
|
a.append("social")
|
|
|
|
|
a.append('entries/feature/' + article)
|
|
|
|
|
a.append(path)
|
|
|
|
|
result.append(a)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
@ -44,31 +52,34 @@ def count_lines(fname):
|
|
|
|
|
|
|
|
|
|
def find_content(article, length, head, tail):
|
|
|
|
|
content = ""
|
|
|
|
|
with open('entries/feature/' + article) as f:
|
|
|
|
|
with open('entries/' + article) as f:
|
|
|
|
|
for pos, line in enumerate(f):
|
|
|
|
|
if pos > head + 1 and pos < length - tail:
|
|
|
|
|
content += line
|
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
|
def snip_article(article):
|
|
|
|
|
def clean(result, path):
|
|
|
|
|
result = result.replace('<br>','')
|
|
|
|
|
result = re.sub(r'<a href=.*?>', '', result)
|
|
|
|
|
result = result.replace('</a>','')
|
|
|
|
|
result = re.sub(r'<h\d>','',result)
|
|
|
|
|
result = re.sub(r'</h\d>','',result)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def snip_article(article, path):
|
|
|
|
|
article = clean(article, path)
|
|
|
|
|
limit = 300
|
|
|
|
|
result = article[0:min(len(article),limit)]
|
|
|
|
|
result = result.replace('<br>','')
|
|
|
|
|
result = result.rsplit(' ',1)[0]
|
|
|
|
|
# cut off after 5 lines, too?
|
|
|
|
|
return result + " ... "
|
|
|
|
|
|
|
|
|
|
def sort_files(files):
|
|
|
|
|
sort = files
|
|
|
|
|
return sort
|
|
|
|
|
return list(reversed(files))
|
|
|
|
|
|
|
|
|
|
def gather_files():
|
|
|
|
|
files = []
|
|
|
|
|
feature = os.listdir('entries/feature/')
|
|
|
|
|
for f in feature:
|
|
|
|
|
files.append('entries/feature/' + f)
|
|
|
|
|
weekly = os.listdir('entries/weekly/')
|
|
|
|
|
for f in weekly:
|
|
|
|
|
files.append('entries/weekly/' + f)
|
|
|
|
|
files = os.listdir('entries/')
|
|
|
|
|
files.remove('raw')
|
|
|
|
|
return files
|
|
|
|
|
|
|
|
|
|
# Static
|
|
|
|
|