@ -1,10 +1,9 @@
import datetime , os , re
import datetime , os , re
from bottle import error , route , run , static_file , template
from bottle import error , route , run , static_file , template , TEMPLATE_PATH
loc = ' diary/ entries/'
loc = ' entries/'
def list_headlines ( articles ) :
def list_headlines ( articles ) :
head = count_lines ( loc + ' raw/res/head.txt ' )
result = [ ]
result = [ ]
text = [ ]
text = [ ]
@ -16,15 +15,19 @@ def list_headlines(articles):
b = [ ]
b = [ ]
b . append ( path )
b . append ( path )
b . append ( clean ( text [ head ] . replace ( ' <br> ' , ' ' ) ) )
b . append ( clean ( text [ 0 ] . replace ( ' <br> ' , ' ' ) ) )
result . append ( b )
result . append ( b )
return result
return result
def retrieve_article ( page ) :
text = [ ]
with open ( loc + page ) as f :
text = f . readlines ( )
return text
def list_snippets ( articles ) :
def list_snippets ( articles ) :
limit = 4
limit = 4
total = len ( articles )
total = len ( articles )
head = count_lines ( loc + ' raw/res/head.txt ' )
tail = count_lines ( loc + ' raw/res/tail.txt ' )
result = [ ]
result = [ ]
for article in articles :
for article in articles :
@ -35,15 +38,15 @@ def list_snippets(articles):
with open ( loc + article ) as f :
with open ( loc + article ) as f :
text = f . readlines ( )
text = f . readlines ( )
length = len ( text )
length = len ( text )
a . append ( clean ( text [ head ] ) ) # title
a . append ( clean ( text [ 0 ] ) ) # title
content = snip_article ( find_content ( article , length , head , tail ), path )
content = snip_article ( find_content ( article , length ), path )
if content . count ( ' <ul> ' ) > content . count ( ' </ul> ' ) :
if content . count ( ' <ul> ' ) > content . count ( ' </ul> ' ) :
content + = ' </ul> '
content + = ' </ul> '
a . append ( content ) # snippet
a . append ( content ) # snippet
a . append ( text [ head + 1 ] . replace ( ' <br> ' , ' ' ) ) # timestamp
a . append ( text [ 1 ] . replace ( ' <br> ' , ' ' ) ) # timestamp
a . append ( ' / ' + path . replace ( ' .tpl ' , ' ' ) ) # URL
a . append ( ' / ' + path . replace ( ' .tpl ' , ' ' ) ) # URL
a . append ( clean ( text [ head ] ) . replace ( ' ' , ' + ' ) ) # social media title
a . append ( clean ( text [ 0 ] ) . replace ( ' ' , ' + ' ) ) # social media title
result . append ( a )
result . append ( a )
return result
return result
@ -53,11 +56,11 @@ def count_lines(fname):
pass
pass
return linenum
return linenum
def find_content ( article , length , head , tail ):
def find_content ( article , length ):
content = " "
content = " "
with open ( loc + article ) as f :
with open ( loc + 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 > 1 and pos < length :
content + = line
content + = line
return content
return content
@ -131,11 +134,16 @@ def diary(page):
info = { ' css ' : ' diary ' , ' title ' : ' blessfrey - developer diary ' , ' year ' : datetime . datetime . now ( ) , ' snippets ' : list_snippets ( sort_files ( gather_files ( ) ) ) , ' latest ' : list_headlines ( sort_files ( gather_files ( ) ) [ 0 : 5 ] ) , ' total ' : len ( gather_files ( ) ) , ' limit ' : 4 , ' cluster ' : 3 , ' page ' : page }
info = { ' css ' : ' diary ' , ' title ' : ' blessfrey - developer diary ' , ' year ' : datetime . datetime . now ( ) , ' snippets ' : list_snippets ( sort_files ( gather_files ( ) ) ) , ' latest ' : list_headlines ( sort_files ( gather_files ( ) ) [ 0 : 5 ] ) , ' total ' : len ( gather_files ( ) ) , ' limit ' : 4 , ' cluster ' : 3 , ' page ' : page }
return template ( ' diary.tpl ' , info )
return template ( ' diary.tpl ' , info )
@route ( ' diary /entries/<page>' )
@route ( ' /entries/<page:int >' )
def entry ( page ) :
def entry ( page ) :
""" diary entry """
info = { ' css ' : ' box ' , ' title ' : ' blessfrey - credits ' , ' year ' : datetime . datetime . now ( ) }
info = { ' css ' : ' diary ' , ' title ' : ' blessfrey - developer diary ' , ' year ' : datetime . datetime . now ( ) , ' latest ' : list_headlines ( sort_files ( gather_files ( ) ) [ 0 : 5 ] ) , ' page ' : page }
abs_app_dir_path = os . path . dirname ( os . path . realpath ( __file__ ) )
return template ( ' feature.tpl ' , info )
abs_views_path = os . path . join ( abs_app_dir_path , ' views ' )
TEMPLATE_PATH . insert ( 0 , abs_views_path )
return template ( os . path . join ( abs_views_path , ' contact.tpl ' ) , info )
# """diary entry"""
# info = {'css': 'diary', 'title': 'blessfrey - developer diary', 'year': datetime.datetime.now(), 'entry': retrieve_article(page), 'latest': list_headlines(sort_files(gather_files())[0:5]), 'page': page}
# return template('feature.tpl', info)
@route ( ' /box ' )
@route ( ' /box ' )
def box ( ) :
def box ( ) :