Re: [patch] pubDate defaulting

Kimbro Staken <[email protected]> Sun, 5 Oct 2003 20:05:53 -0700
Newsgroups gmane.comp.web.syncato.general
Message-ID <[email protected]>
On Sunday, October 5, 2003, at 10:47  AM, Rick Bradley wrote:

> This is a patch to dist/scripts/lib/Weblog.py from the 0.5 release of
> Syncato to only set the pubDate element of a new document if there is
> not already a pubDate element set.  Using XPath to check for element
> existence may be a sledgehammer, but that's the only way I could 
> quickly
> see to do it.

It's not a sledgehammer, it's using a powerful abstraction. That's a 
large part of the point of this system is to show the power of XPath 
not just for queries, but also for general development. I intentionally 
used XPath for everything, even in cases where I know there are much 
better performing ways of doing things.

Thanks for the patch, this was on my todo list.

>
> I had factored it out for use when editing the document as well but
> decided to presume that documents aren't entering the database via 
> means
> other than Weblog.py (presuming further that You Know What You're Doing
> if such is the case), and so will have a pubDate set if they're in the
> database already.
>
>
> --- Weblog.py	2003-10-05 12:36:08.000000000 -0500
> +++ Weblog.py-new	2003-10-05 12:40:44.000000000 -0500
> @@ -88,25 +88,26 @@
>      def addPost(self, post):
>          try:
>              doc = libxml2.parseDoc(post)
> -
> -            root = doc.getRootElement()
> -
> -            date = time.time()
> -            # ISO8601 Date
> -            # TODO this shouldn't really use localtime as the ISO8601 
> date should be GMT. Just not sure how to
> -            # convert the time using XSL-T otherwise.
> -            pubDate = root.newChild(None, "pubDate", 
> time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(date)) + "-07:00")
> -
> -            pubDate.setProp("seconds", str(date))
> -
> +
> +            # add pubDate element if none found
> +            if (0 == 
> len(doc.xpathNewContext().xpathEval("//pubDate"))):
> +                root = doc.getRootElement()
> +                date = time.time()
> +                # ISO8601 Date
> +                # TODO this shouldn't really use localtime as the 
> ISO8601 date should be GMT. Just not sure how to
> +                # convert the time using XSL-T otherwise.
> +                pubDate = root.newChild(None, "pubDate", 
> time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(date)) + "-07:00")
> +                pubDate.setProp("seconds", str(date))
> +
> +            # and add to database
>              postID = self.db.addRecord(doc)
> -
>              doc.freeDoc()
> -
> +
>              # Send change notification to other sites
>              self.pingWeblogs()
>
>              return postID
> +
>          except Exception, e:
>              print str(e)
>              raise e
>
>
> Rick
> -- 
>  http://www.rickbradley.com    MUPRN: 730
>                        |  will be doing with their
>    random email haiku  |  room before and after the
>                        |  Installfest, etc). Thanks.
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Syncato-general mailing list
> Syncato-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/syncato-general
>
>
Kimbro Staken
Software, Consulting and Writing http://www.xmldatabases.org/
Apache Xindice native XML database http://xml.apache.org/xindice
XML:DB Initiative http://www.xmldb.org



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf