|
|
|
import datetime, os
|
|
|
|
from bottle import error, route, run, static_file, template
|
|
|
|
|
|
|
|
# write diary
|
|
|
|
|
|
|
|
def build_nav():
|
|
|
|
return "nav"
|
|
|
|
|
|
|
|
def make_latest():
|
|
|
|
# for article in array (just 5 or something)
|
|
|
|
# link to webpage
|
|
|
|
return "latest"
|
|
|
|
|
|
|
|
def list_snippets(articles):
|
|
|
|
# take articles between 0-4, 5-8, 9-13,...) based on current page
|
|
|
|
# for each one of those articles,
|
|
|
|
# snip_article(article)
|
|
|
|
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(find_content(article, length, head, tail)))
|
|
|
|
a.append(text[head + 1])
|
|
|
|
a.append("social")
|
|
|
|
a.append('entries/feature/' + article)
|
|
|
|
result.append(a)
|
|
|
|
return result
|
|
|
|
|
|
|
|
def count_lines(fname):
|
|
|
|
with open(fname) as f:
|
|
|
|
for linenum, line in enumerate(f,1):
|
|
|
|
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 + 1 and pos < length - tail:
|
|
|
|
content += line
|
|
|
|
return content
|
|
|
|
|
|
|
|
def snip_article(article):
|
|
|
|
limit = 300
|
|
|
|
result = article[0:min(len(article),limit)]
|
|
|
|
result = result.replace('<br>','')
|
|
|
|
result = result.rsplit(' ',1)[0]
|
|
|
|
return result + " ... "
|
|
|
|
|
|
|
|
def sort_files(files):
|
|
|
|
m = list(reversed(files))
|
|
|
|
return files
|
|
|
|
|
|
|
|
def gather_files():
|
|
|
|
return os.listdir('entries/feature/')
|
|
|
|
|
|
|
|
# Static
|
|
|
|
|
|
|
|
@route('/static/css/<filename:path>')
|
|
|
|
def serve_css(filename):
|
|
|
|
return static_file(filename, root='static/css')
|
|
|
|
|
|
|
|
@route('/static/img/<filename:path>')
|
|
|
|
def serve_css(filename):
|
|
|
|
return static_file(filename, root='static/img')
|
|
|
|
|
|
|
|
# Routes
|
|
|
|
|
|
|
|
@error(404)
|
|
|
|
def error404(error):
|
|
|
|
return "unfortunately, a 404 error"
|
|
|
|
|
|
|
|
@route('/')
|
|
|
|
def index():
|
|
|
|
"""home page"""
|
|
|
|
info = {'css': 'index', 'news': 'News goes here', 'title': 'chimchooree\'s dev space - blessfrey', 'year': datetime.datetime.now()}
|
|
|
|
return template('index.tpl', info)
|
|
|
|
|
|
|
|
@route('/game')
|
|
|
|
def game():
|
|
|
|
"""game page"""
|
|
|
|
info = {'title': 'blessfrey - about the game', 'year': datetime.datetime.now()}
|
|
|
|
return template('game.tpl', info)
|
|
|
|
|
|
|
|
@route('/presskit')
|
|
|
|
def presskit():
|
|
|
|
"""press page"""
|
|
|
|
info = {'title': 'blessfrey - presskit', 'year': datetime.datetime.now()}
|
|
|
|
return template('presskit.tpl', info)
|
|
|
|
|
|
|
|
@route('/diary')
|
|
|
|
def diary():
|
|
|
|
"""diary page"""
|
|
|
|
info = {'title': 'blessfrey - about the game', 'year': datetime.datetime.now(), 'snippets': list_snippets(sort_files(gather_files())), 'latest': make_latest()}
|
|
|
|
return template('diary.tpl', info)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run()
|