Re: dates in filenames?

"Tung Wai Yip" <tungwaiyip-/[email protected]>
Newsgroups gmane.comp.web.pyblosxom.user
Message-ID <[email protected]>
> Someone else mentioned using email as a entry format.  I don't know if  
> they got around to building an entryparser for that or not.
>
> /will

Yes this is the very simple plugin I'm using. I plan to release it once I  
got to save the meta data in an index file. But I still haven't get the  
time to do so. Maybe someone would interested to extend it. The intented  
file format is:

----------------------------------------------
Subject: A sample entry
Date: 2004-09-28
Status: draft
Summary: Add a few short lines to
   describe this entry. Give user some idea what this entry is about
   before they click to view the full entry

This is the body of the entry.
It has many many lines.
----------------------------------------------

Also the plugin need to make the email header available as the entry's  
meta to make it useful for pyBlosxom.

Wai Yip
pyMsg.py (application/octet-stream, 1.4 KB)
import email
import email.Utils
import os, re, time
import sys

__author__ = 'Wai Yip Tung http://tungwaiyip.info'
__version__ = '$Id: pymsg.py, v0.10 2004/07/10 10:25 tungwaiyip Exp $'

def verify_installation(request):
    # there's no configuration needed for this plugin.
    return 1

def cb_entryparser(args):
    args["txt"] = parseMessage
    return args

formats = [
  '%Y-%m-%dT%H:%M:%S%Z',
  '%Y-%m-%dT%H:%M:%S',
  '%Y-%m-%dT%H:%M',
  '%Y-%m-%d',
]

def parseTime(s):
    # Try RFC2822
    # Date: Wed, 25 Feb 2004 16:34:12 -0800
    mtime = email.Utils.parsedate(s)
    if mtime: return mtime

    # Try ISO8601
    # Date: 2002-12-23T08:32-08:00
    for f in formats:
        try:
            mtime = time.strptime(s, f)
            return mtime
        except ValueError:
            pass
    return None

def parseMessage(filename, request):
    f = open(filename, "r")
    msg = email.message_from_file(f)
    data = {'title': msg.get('Subject'),
            'body': msg.get_payload()}
    return data

def cb_filestat(args):
    filename = args["filename"]
    stattuple = args["mtime"]

    f = open(filename, "r")
    msg = email.message_from_file(f)
    date = msg.get('Date')
    if not date:
        return args
    mtime = parseTime(date)
    if mtime:
        mtime = time.mktime(mtime)
        args["mtime"] = tuple(list(stattuple[:8]) + [mtime] + list(stattuple[9:]))
    return args
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.