remove html links from snippets; if <ul> is greater than </ul>'s count, add </ul> to snippet content
This commit is contained in:
+21
-8
@@ -1,4 +1,4 @@
|
||||
import datetime, os
|
||||
import datetime, os, re
|
||||
from bottle import error, route, run, static_file, template
|
||||
|
||||
# make article-to-html work with entries
|
||||
@@ -25,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)))
|
||||
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("social")
|
||||
a.append('entries/feature/' + article)
|
||||
a.append(path)
|
||||
result.append(a)
|
||||
return result
|
||||
|
||||
@@ -47,16 +52,22 @@ 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>','')
|
||||
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]
|
||||
return result + " ... "
|
||||
|
||||
@@ -65,7 +76,9 @@ def sort_files(files):
|
||||
return files
|
||||
|
||||
def gather_files():
|
||||
return os.listdir('entries/feature/')
|
||||
files = os.listdir('entries/')
|
||||
files.remove('raw')
|
||||
return files
|
||||
|
||||
# Static
|
||||
|
||||
|
||||
Reference in New Issue
Block a user