article footer file is named 'tail;' snippet shows title, full text, and link
This commit is contained in:
@@ -9,7 +9,7 @@ def file_to_string(f):
|
||||
return text
|
||||
|
||||
def fill_text(f):
|
||||
return file_to_string('../res/head.txt') + file_to_string(f) + file_to_string('../res/foot.txt')
|
||||
return file_to_string('../res/head.txt') + file_to_string(f) + file_to_string('../res/tail.txt')
|
||||
|
||||
def create_files(files, directory):
|
||||
for f in files:
|
||||
|
||||
+14
-5
@@ -18,20 +18,21 @@ def list_snippets(articles):
|
||||
limit = 4
|
||||
total = len(articles)
|
||||
head = count_lines('entries/raw/res/head.txt')
|
||||
tail = count_lines('entries/raw/res/tail.txt')
|
||||
result = []
|
||||
|
||||
for article in articles:
|
||||
text = []
|
||||
a = []
|
||||
|
||||
length = 0
|
||||
with open('entries/feature/' + article) as f:
|
||||
text = f.readlines()
|
||||
|
||||
length = len(text)
|
||||
a.append(text[head])
|
||||
a.append(snip_article("words words words"))
|
||||
a.append("11/22/33")
|
||||
a.append(snip_article(find_content(article, length, head, tail)))
|
||||
a.append(text[head + 1])
|
||||
a.append("social")
|
||||
a.append("link")
|
||||
a.append('entries/feature/' + article)
|
||||
result.append(a)
|
||||
return result
|
||||
|
||||
@@ -41,6 +42,14 @@ def count_lines(fname):
|
||||
pass
|
||||
return linenum
|
||||
|
||||
def find_content(article, length, head, tail):
|
||||
content = ""
|
||||
with open('entries/feature/' + article) as f:
|
||||
for pos, line in enumerate(f):
|
||||
if pos > head and pos < length - tail:
|
||||
content += line
|
||||
return content
|
||||
|
||||
def snip_article(article):
|
||||
# read text in article
|
||||
# clean 250 first characters
|
||||
|
||||
Reference in New Issue
Block a user