From c25691b30169518ad836e78d844ecd34542cf645 Mon Sep 17 00:00:00 2001 From: Drew Fisher Date: Wed, 5 Jan 2011 13:49:16 -0600 Subject: [PATCH] Import of running code as of 2011-01-05. It seemed a really bad idea to NOT have this in version control, and it also was hindering deployment. --- comments/.gitignore | 1 + entries/.gitignore | 1 + pending/.gitignore | 0 shortlog.py | 259 ++++++++++++++++++++++++++++++++++++++++ static/.gitignore | 2 + templates/day.html | 42 +++++++ templates/feed.xml | 22 ++++ templates/multiday.html | 24 ++++ templates/noentry.html | 13 ++ 9 files changed, 364 insertions(+) create mode 100644 comments/.gitignore create mode 100644 entries/.gitignore create mode 100644 pending/.gitignore create mode 100644 shortlog.py create mode 100644 static/.gitignore create mode 100644 templates/day.html create mode 100644 templates/feed.xml create mode 100644 templates/multiday.html create mode 100644 templates/noentry.html diff --git a/comments/.gitignore b/comments/.gitignore new file mode 100644 index 0000000..2211df6 --- /dev/null +++ b/comments/.gitignore @@ -0,0 +1 @@ +*.txt diff --git a/entries/.gitignore b/entries/.gitignore new file mode 100644 index 0000000..2211df6 --- /dev/null +++ b/entries/.gitignore @@ -0,0 +1 @@ +*.txt diff --git a/pending/.gitignore b/pending/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/shortlog.py b/shortlog.py new file mode 100644 index 0000000..a341b66 --- /dev/null +++ b/shortlog.py @@ -0,0 +1,259 @@ +#!/usr/bin/env python + +import web +import os +import datetime +import re +import smtplib +import md5 + +pwd = os.path.dirname( os.path.realpath( __file__ ) ) + +web.config.debug = True + +monthnames = {"01": "January", + "02": "February", + "03": "March", + "04": "April", + "05": "May", + "06": "June", + "07": "July", + "08": "August", + "09": "September", + "10": "October", + "11": "November", + "12": "December"} + +urls = ( + '/', 'pastweek', + '/week', 'pastweek' , + '/month', 'pastmonth' , + '/year', 'pastyear' , + '/feed', 'feed' , + '/(\d\d\d\d)/(\d\d)/(\d\d)', 'day' , + '/(\d\d\d\d)-(\d\d)-(\d\d)', 'day' , + '/(\d\d\d\d)/(\d\d)', 'month' , + '/(\d\d\d\d)', 'year', + '', 'redir', + ) + +## This is the way to do it in web.py 0.3+ +#app = web.application(urls, globals()) + +## Workaround for autoreloading and sessions when using web.config.debug = True +## Note: I don't actually use sessions +#if web.config.get("_session") is None: +# session = web.session.Session(app, web.session.DiskStore('sessions'), initializer={'count': 0}) +# web.config._session = session +#else: +# session = web.config._session + +# read the paragraphs from a file +def readFile(filepath): + f = open(filepath) + lines = map(str.strip, f.readlines()) + return makeParas(lines) + +def loadComment(filepath): + f = open(filepath) + nameline = f.readline().strip() + emailline = f.readline().strip() + websiteline = f.readline().strip() + timestamp = f.readline().strip() + commentbody = makeParas(map(str.strip, f.readlines())) + m = md5.new() + m.update(emailline.lower()) + gravatar = "http://www.gravatar.com/avatar/%s?s=48&d=identicon" % str(m.hexdigest()) + #timestamp = datetime.datetime.fromtimestamp(os.stat(filepath).st_mtime).isoformat() + return (nameline, emailline, websiteline, commentbody, timestamp, gravatar) + +def getCommentFiles(date): # Returns a list of paths to comment files associated with date + filelist = filter( lambda x: re.match(date, x), os.listdir(pwd + "/comments")) + return filelist + +# Collect lines into paragraph blocks. Returns a list of strings, each containing a well-formed HTML block. +def makeParas(lines): + paragraphs = [] + thispara = [] + for line in lines: + if len(line) != 0: + thispara.append(line) + else: + paragraphs.append("\n".join(thispara)) + thispara = [] + if len(thispara) > 0: + paragraphs.append("\n".join(thispara)) + + # wrap paragraphs in

if they aren't other HTML tags that don't want to be wrapped in

tags + return map( lambda x: x if "

    " in x or "