Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Nov. 23, 2005 16:49:34

t.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Atom and web services interfaces


Hello,

I'm thinking of using Django as the front-end to an experimental
Atom-enabled 'store' as outlined by Joe Gregorio athttp://www.xml.com/pub/a/2005/09/21/atom-store-web-database.htmlI'm a real newbie to Django, having spent the last 7 years in
Zope-land, and am looking at Django as an adjunct to the many many Zope
systems we run here (I just had reason to play around with
PageTemplates and PythonScripts this morning and the frustration was
intense!)

Any thoughts gratefully received.

Tone

Offline

#2 Nov. 23, 2005 21:00:57

Adrian H.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Atom and web services interfaces


On 11/23/05, tonemcd <> wrote:
> I'm thinking of using Django as the front-end to an experimental
> Atom-enabled 'store' as outlined by Joe Gregorio at
>http://www.xml.com/pub/a/2005/09/21/atom-store-web-database.html>
> Any thoughts gratefully received.

Hi Tone,

Django's very REST-friendly, so the task should be straightforward.
Feel free to post specific questions, and keep us posted on how it's
coming!

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Offline

#3 Nov. 25, 2005 07:25:03

t.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Atom and web services interfaces


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
-->
-->
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?

Offline

#4 Nov. 25, 2005 10:28:11

oggie r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Atom and web services interfaces


Looks like you are passing in a string object for the date.
feedgenerator.rfc3339_date(when) will return a string rather than a
datetime object, I'm guessing that is the problem.

-rob

Offline

#5 Nov. 25, 2005 11:56:25

t.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Atom and web services interfaces


Thanks for the reply Rob - yup it's a string all right, but the only
time *I* pass anything to rfc3399 is when I pass it a datetime.datetime
object.

It seems that the routine feedgenerator.writeString is sending rfc3399
a string rather than a datetime.datetime object, which it gets from the
write method of Atom1Feed - the relevant bit is here...

handler.addQuickElement(u"updated",
rfc3339_date(self.latest_post_date()).decode('ascii'))

Which leads to this (with my debug prints);

def latest_post_date(self):
"""
Returns the latest item's pubdate. If none of them have a
pubdate,
this returns the current date/time.
"""
updates = [i for i in self.items if i is
not None]
print "UPDATES", updates
if len(updates) > 0:
updates.sort()
print "updates:", type(updates)
return updates
else:
print "datetime.datetime.now()", datetime.datetime.now()
return datetime.datetime.now()

What happens now?

Well, this;

UPDATES
updates: <type 'str'>

Which leads to the blow-up.

I would have thought that other people would have seen this which is
why I re-iterate "what stupid thing am I doing here?" ;)

many thanks
Tone

Offline

#6 Nov. 25, 2005 23:11:36

oggie r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Atom and web services interfaces


> Thanks for the reply Rob - yup it's a string all right, but the only
time *I* pass anything to rfc3399 is when I pass it a datetime.datetime
object.

Okay, but I meant the add_item method wants a datetime. From your
original post:
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,
)

Looks like pubdate is supposed to be a datetime object, but clearly the
result of feedgenerator.rfc3339_date() is a string. Try this instead:
f.add_item(title=u"Hot dog today",
link = u"http://www.example.com/entries/1/";,
pubdate = when,
description = u"<p>sort it out son!</p>",
enclosure = myenclosure,
unique_id = None,
)

Note that I haven't used this feed stuff yet, so I'm not sure if this
is ultimately what you want to do - but at least I think it will solve
the problem you're having!

-rob

Offline

#7 Nov. 26, 2005 06:42:20

t.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Atom and web services interfaces


Groan! - just starting out on my Django career and already falling
victim to the "didn't read the dcoumentation" disease!

Thanks very much indeed Rob, it works fine now!

cheers
Tone

Offline

Board footer

Moderator control

Enjoy the 20th of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support