The Artima Developer Community
Sponsored Link

Python Buzz Forum
My Data I Wanna

0 replies.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a flat view of this topic  Flat View
Previous Topic   Next Topic
Threaded View: This topic has 0 replies on 1 page
Ng Pheng Siong

Posts: 410
Nickname: ngps
Registered: Apr, 2004

Ng Pheng Siong is just another guy with a website.
My Data I Wanna Posted: Aug 23, 2004 1:47 AM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Ng Pheng Siong.
Original Post: My Data I Wanna
Feed Title: (render-blog Ng Pheng Siong)
Feed URL: http://sandbox.rulemaker.net/ngps/rdf10_xml
Feed Description: Just another this here thing blog.
Latest Python Buzz Posts
Latest Python Buzz Posts by Ng Pheng Siong
Latest Posts From (render-blog Ng Pheng Siong)

This blog is powered by COREBlog, a Zope product. Blog entries are persistent Python objects stored in Zope's ZODB.

Let's say I wish to keep a copy of each entry in a separate file in the local filesystem.

One way is to fetch it through the web:

$ curl -o 1.html http://sandbox.rulemaker.net/1

This saves blog entry '1' into the file 1.html.

To get the lot:

$ for ((i=1; i<=$last; i++))
do
curl -o $i.html http://sandbox.rulemaker.net/$i
done
$

Each html file contains the rendered entry, complete with headers, footers and Google ad. More work is needed if I want just the entry body itself, such as parsing the HTML, or crafting a DTML method or Python script within Zope to display just the body.

Another way is to read it from (a copy of) the ZODB. On my desktop, I have a local Zope installed into ~/pkg/zope. First I get my blog entries into this Zope, either by importing from the live Zope, or by copying over the entire ZODB file itself.

Then, invoke Python:

$ python2.1
Python 2.1.3 (#2, Jun 10 2003, 00:24:34) 
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.insert(0,'/home/ngps/pkg/zope/lib/python')
>>> import Zope
>>> root = Zope.app()

Now 'root' points to Zope's root folder. Traverse to the blog:

>>> coreblog = root['sandbox.rulemaker.net']['ngps']['blog']
>>> coreblog
<COREBlog instance at 91c7880>
>>> e = coreblog.entries[1]
>>> e
<Entry instance at 91cd280>
>>> e.title
'Winds Of Change'
>>> e.body   
"So, I have decided this web site needs some reworking.\n\n..."
>>> e.created
1078502400
>>> import time
>>> time.ctime(e.created)
'Sat Mar  6 00:00:00 2004'

I have the title, the body, the body's format - either plain text, StructuredText or HTML - and the timestamp. Looks like the lot. From here it is just a little more work to package the above into a program that extracts all the entries, comments and trackbacks.

The above cannot be done while that particular ZODB is running, i.e., in use by Zope. If I have Zope Enterprise Objects (ZEO) set up, then I can, by acting as a ZEO client. This is almost like having REPL access to a Common Lisp web server.

Read: My Data I Wanna


Topic: TurboGears Sprint Saturday Previous Topic   Next Topic Topic: Nexenta - dtrace not quite working yet

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use