From a24e8e8426530a265de81a38bcf7ecf6f60f8ce9 Mon Sep 17 00:00:00 2001 From: Mimi Momo Date: Thu, 1 Oct 2020 13:28:10 -0500 Subject: [PATCH] remove html links from snippets; if 's count, add to snippet content --- src/index.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/index.py b/src/index.py index 231dfb9..376b64c 100644 --- a/src/index.py +++ b/src/index.py @@ -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(''): + content += '' + 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('
','') + result = re.sub(r'', '', result) + result = result.replace('','') + return result + +def snip_article(article, path): + article = clean(article, path) limit = 300 result = article[0:min(len(article),limit)] - result = result.replace('
','') 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