|
|
@ -1,4 +1,4 @@
|
|
|
|
import datetime, os
|
|
|
|
import datetime, os, re
|
|
|
|
from bottle import error, route, run, static_file, template
|
|
|
|
from bottle import error, route, run, static_file, template
|
|
|
|
|
|
|
|
|
|
|
|
# make article-to-html work with entries
|
|
|
|
# make article-to-html work with entries
|
|
|
@ -25,17 +25,22 @@ def list_snippets(articles):
|
|
|
|
result = []
|
|
|
|
result = []
|
|
|
|
|
|
|
|
|
|
|
|
for article in articles:
|
|
|
|
for article in articles:
|
|
|
|
|
|
|
|
path = 'entries/' + article
|
|
|
|
text = []
|
|
|
|
text = []
|
|
|
|
a = []
|
|
|
|
a = []
|
|
|
|
length = 0
|
|
|
|
length = 0
|
|
|
|
with open('entries/feature/' + article) as f:
|
|
|
|
with open('entries/' + article) as f:
|
|
|
|
text = f.readlines()
|
|
|
|
text = f.readlines()
|
|
|
|
length = len(text)
|
|
|
|
length = len(text)
|
|
|
|
a.append(text[head])
|
|
|
|
a.append(text[head])
|
|
|
|
a.append(snip_article(find_content(article, length, head, tail)))
|
|
|
|
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])
|
|
|
|
a.append(text[head + 1])
|
|
|
|
a.append("social")
|
|
|
|
a.append("social")
|
|
|
|
a.append('entries/feature/' + article)
|
|
|
|
a.append(path)
|
|
|
|
result.append(a)
|
|
|
|
result.append(a)
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
@ -47,16 +52,22 @@ def count_lines(fname):
|
|
|
|
|
|
|
|
|
|
|
|
def find_content(article, length, head, tail):
|
|
|
|
def find_content(article, length, head, tail):
|
|
|
|
content = ""
|
|
|
|
content = ""
|
|
|
|
with open('entries/feature/' + article) as f:
|
|
|
|
with open('entries/' + article) as f:
|
|
|
|
for pos, line in enumerate(f):
|
|
|
|
for pos, line in enumerate(f):
|
|
|
|
if pos > head + 1 and pos < length - tail:
|
|
|
|
if pos > head + 1 and pos < length - tail:
|
|
|
|
content += line
|
|
|
|
content += line
|
|
|
|
return content
|
|
|
|
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>','')
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def snip_article(article, path):
|
|
|
|
|
|
|
|
article = clean(article, path)
|
|
|
|
limit = 300
|
|
|
|
limit = 300
|
|
|
|
result = article[0:min(len(article),limit)]
|
|
|
|
result = article[0:min(len(article),limit)]
|
|
|
|
result = result.replace('<br>','')
|
|
|
|
|
|
|
|
result = result.rsplit(' ',1)[0]
|
|
|
|
result = result.rsplit(' ',1)[0]
|
|
|
|
return result + " ... "
|
|
|
|
return result + " ... "
|
|
|
|
|
|
|
|
|
|
|
@ -65,7 +76,9 @@ def sort_files(files):
|
|
|
|
return files
|
|
|
|
return files
|
|
|
|
|
|
|
|
|
|
|
|
def gather_files():
|
|
|
|
def gather_files():
|
|
|
|
return os.listdir('entries/feature/')
|
|
|
|
files = os.listdir('entries/')
|
|
|
|
|
|
|
|
files.remove('raw')
|
|
|
|
|
|
|
|
return files
|
|
|
|
|
|
|
|
|
|
|
|
# Static
|
|
|
|
# Static
|
|
|
|
|
|
|
|
|
|
|
|