#!/usr/bin/python import os import time import subprocess import re import mistune import chatter SOURCE = os.path.join("/home", "endorphant", "projects", "ttbp", "bin") USER = os.path.basename(os.path.expanduser("~")) PATH = os.path.join("/home", USER, ".ttbp") LIVE = "http://tilde.town/~" WWW = os.path.join(PATH, "www") CONFIG = os.path.join(PATH, "config") DATA = os.path.join(PATH, "entries") HEADER = "" FOOTER = "" FILES = [] MONTHS = { "01":"january", "02":"february", "03":"march", "04":"april", "05":"may", "06":"june", "07":"july", "08":"august", "09":"september", "10":"october", "11":"november", "12":"december" } def load(): global HEADER global FOOTER HEADER = open(os.path.join(CONFIG, "header.txt")).read() FOOTER = open(os.path.join(CONFIG, "footer.txt")).read() load_files() def load_files(): global FILES FILES = [] for filename in os.listdir(DATA): filename = os.path.join(DATA, filename) if os.path.isfile(filename) and valid(filename): FILES.append(filename) FILES.sort() FILES.reverse() def write(outurl="default.html"): outfile = open(os.path.join(WWW, outurl), "w") outfile.write("\n\n") for line in HEADER: outfile.write(line) outfile.write("\n") for filename in FILES: write_page(filename) for line in write_entry(filename): outfile.write(line) outfile.write("\n") for line in FOOTER: outfile.write(line) outfile.close() return os.path.join(LIVE+USER,os.path.basename(os.path.realpath(WWW)),outurl) def write_page(filename): # makes a single permalink page outurl = os.path.join(WWW, "".join(parse_date(filename))+".html") outfile = open(outurl, "w") outfile.write("\n\n") for line in HEADER: outfile.write(line) outfile.write("\n") for line in write_entry(filename): outfile.write(line) outfile.write("\n") for line in FOOTER: outfile.write(line) outfile.close() return outurl def write_entry(filename): # dump given file into entry format, return as list of strings date = parse_date(filename) entry = [ "\t\t
\n", "\t\t" ] raw = [] rawfile = open(os.path.join(DATA, filename), "r") for line in rawfile: raw.append(line) rawfile.close() entry.append("\t\t\t"+mistune.markdown("".join(raw), escape=False, hard_wrap=False)) #for line in raw: #entry.append(line+"\t\t\t") #if line == "\n": # entry.append("
\n\t\t\t") #entry.append("
\n") entry.append("\t\t\t\n") entry.append("\n\t\t