Oh yes, I figured that Django would be very RESTian-friendly from the
URL dispatching. I did some digging around for Atom publishing modules
(parsing seems to be pretty well taken care of with feedparser and
ElementTree) and after some false starts, I found quite a good
publisher in ... django! (d'oh!). It's clean and relatively simple to
follow. For those who don't know it's in
utils.feedgenerator.py.

Thing is, there seems to be something amiss;

from django.utils import feedgenerator
import datetime

f = feedgenerator.Atom1Feed(
     title = u"My Weblog",
     link = u"http://www.example.com/";,
     description = u"In which I write about what I ate today.",
     categories = ('sex', 'drugs', 'rock and roll'),
     language = u"en",
     )

myenclosure = feedgenerator.Enclosure(
    url =
u'https://resourcebank.ncl.ac.uk/resource/access/download/fa85c3c1-0ff5-466c-8cb1-83936d4b1b93/CPT_presentation_Case_B_-_Group_3.ppt',
    length = u'1019821',
    mime_type = u'application/powerpoint',
    )

when = datetime.datetime(2005,11,24)
print when

f.add_item(title=u"Hot dog today",
    link = u"http://www.example.com/entries/1/";,
    pubdate = feedgenerator.rfc3339_date(when),
    description = u"<p>sort it out son!</p>",
    enclosure = myenclosure,
    unique_id = None,
    )

print f.writeString('utf8')


The resourcebank link does not exist ;)

What comes out is this;

2005-11-24 00:00:00
--> ['__add__', '__class__', '__delattr__', '__doc__', '__eq__',
'__ge__', '__getattribute__', '__gt__', '__hash__', '__init__',
'__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__',
'__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__str__',
'__sub__', 'astimezone', 'combine', 'ctime', 'date', 'day', 'dst',
'fromordinal', 'fromtimestamp', 'hour', 'isocalendar', 'isoformat',
'isoweekday', 'max', 'microsecond', 'min', 'minute', 'month', 'now',
'replace', 'resolution', 'second', 'strftime', 'time', 'timetuple',
'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp',
'utcnow', 'utcoffset', 'utctimetuple', 'weekday', 'year']
--> ['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__ge__', '__getattribute__', '__getitem__',
'__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__',
'__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__',
'__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count',
'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index',
'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle',
'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind',
'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitlines',
'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper',
'zfill']
Traceback (most recent call last):
  File "/Users/tonymcd/Projects/Python/atom/django_atom.py", line 29,
in ?
    print f.writeString('utf8')
  File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/utils/feedgenerator.py",
line 99, in writeString
    self.write(s, encoding)
  File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/utils/feedgenerator.py",
line 201, in write
    handler.addQuickElement(u"updated",
rfc3339_date(self.latest_post_date()).decode('ascii'))
  File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/utils/feedgenerator.py",
line 32, in rfc3339_date
    return date.strftime('%Y-%m-%dT%H:%M:%SZ')
AttributeError: 'str' object has no attribute 'strftime'


The --> is a debug line put into feedgenerator.rfc3339

def rfc3339_date(date):
    print "-->", dir(date)
    return date.strftime('%Y-%m-%dT%H:%M:%SZ')

There's two outputs (first when rfc3339 is called in my code and second
when writeString('utf8') takes over).

Can anyone point out where I'm being completely stupid here?

Reply via email to