Re: Doing content-based mtime determination
"Wai Yip Tung" <tungwaiyip-/[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.user |
|---|---|
| Message-ID | <[email protected]> |
Sorry please ignore my last message. Hitted the wrong button! I'm actually doing the something similar. I find using the last modified time as the post time too unstable and date-in-filename not desirable. So I have this plug-in that read a data file as RFC2822 message. Basically just put this two lines in the beginning of every data file: Subject: hello Date: 2004-08-01 The call back to use to update the time is cb_filestat. The caveat is now pyBlosxom is going to read every message to determine its date. If performance is not an issue you can use this plug-in as is. I'm trying to build some kind of index but still having got around to do so. Wai Yip > I was trying to write a plugin that basically determined the effective > mtime of an entry based on an in-entry tag like: > > TIMESTAMP::2002-04-01-00-00 > > I like this approach over the date-in-filename approach because > mucking with the filename means mucking with the URLs of permalinks. > > Unfortunately, it appears that the entry hasn't been parsed by the > time cb_filestat gets called. Is the right approach in this case to > have a cb_filelist handler? It seems it would be too late, and other > plugins which limit things based on date would have gotten it 'wrong' > by the time cb_filelist got called. > > Any advice appreciated. > > --david > > > ------------------------------------------------------- > SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media > 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 > Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. > http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 > _______________________________________________ > pyblosxom-users mailing list > pyblosxom-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
hello.txt
(text/plain, 53 B)
Subject: hello Date: 2004-08-01 This is a test post.
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