Re: w3cdate in flavour head
Matej Cepl <[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.user |
|---|---|
| Message-ID | <[email protected]> |
Steven Armstrong wrote:
> I've hacked my version of w3cdate for just that reason. See attachment.
> You can use $lastmodified_w3cdate in your head.atom flavour.
Do you have to use xml.utils.iso8601? I use pyblosxom on a server, where I
cannot influence that easily what is installed, and they do not have
python-xml package installed there.
What do you think about the attached hack?
matej
--
Matej Cepl, http://www.ceplovi.cz/matej
GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC
138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488
See, when the GOVERNMENT spends money, it creates jobs; whereas
when the money is left in the hands of TAXPAYERS, God only knows
what they do with it. Bake it into pies, probably. Anything to
avoid creating jobs.
-- Dave Barry
w3cdate.py
(text/plain, 2.9 KB)
""" Add a 'w3cdate' key to every entry -- this contains the date in ISO8601 format WARNING: you must have PyXML installed as part of your python installation in order for this plugin to work Place this plugin early in your load_plugins list, so that the w3cdate will be available to subsequent plugins """ __author__ = "Ted Leung <[email protected]>" __version__ = "$Id:" __copyright__ = "Copyright (c) 2003 Ted Leung" __license__ = "Python" import time import rfc822 from Pyblosxom import tools def isodate(t): """Format a time in ISO-8601 format. If `timezone' is specified, the time will be specified for that timezone, otherwise for UTC. Some effort is made to avoid adding text for the 'seconds' field, but seconds are supported to the hundredths. """ timezone = int(time.timezone) if timezone: sign = (timezone < 0) and "+" or "-" timezone = abs(timezone) hours = timezone / (60 * 60) minutes = (timezone % (60 * 60)) / 60 tzspecifier = "%c%02d:%02d" % (sign, hours, minutes) else: tzspecifier = "Z" psecs = t - int(t) t = time.gmtime(int(t) - timezone) year, month, day, hours, minutes, seconds = t[:6] if seconds or psecs: if psecs: psecs = int(round(psecs * 100)) f = "%4d-%02d-%02dT%02d:%02d:%02d.%02d%s" v = (year, month, day, hours, minutes, seconds, psecs, tzspecifier) else: f = "%4d-%02d-%02dT%02d:%02d:%02d%s" v = (year, month, day, hours, minutes, seconds, tzspecifier) else: f = "%4d-%02d-%02dT%02d:%02d%s" v = (year, month, day, hours, minutes, tzspecifier) return f % v def cb_prepare(args): request = args['request'] data = request.getData() try: newest_entry = data.get("entry_list", [])[0] time_tuple = newest_entry['timetuple'] if time_tuple: # /sar: in my setup this can be None tzoffset = time.timezone # if is_dst flag set, adjust for daylight savings time if time_tuple[8] == 1: tzoffset = time.altzone t = time.mktime(time_tuple) request.addData({ 'lastmodified_w3cdate': isodate(t), 'lastmodified_rfc822date': rfc822.formatdate(t) }) except: #tools.log_exception() pass return args def cb_story(args): entry = args['entry'] time_tuple = entry['timetuple'] if time_tuple: # /sa: in my setup this can be None tzoffset = time.timezone # if is_dst flag set, adjust for daylight savings time if time_tuple[8] == 1: tzoffset = time.altzone t = time.mktime(time_tuple) entry['w3cdate'] = isodate(t) # rfc822 date for rss feed entry['rfc822date'] = rfc822.formatdate(t) return args if __name__ == '__main__': print isodate(time.mktime(time.localtime()))