[Zope] RSS feed: post-processing?

MILLER Eva evam at multcolib.org
Tue Apr 5 18:25:55 EDT 2005


Hi,

OK, let me see if I can do that...

I've already figured out that a python script/external method solution
is what I'm after. But how to make it work?

Anyone know about Greasemonkey in Firefox? Basically, it embeds a handy
link in Web pages that have ISBN numbers in them (unique identifier for
a book). When you configure Greasemonkey right, it checks for the book
in your local catalog and returns a link to that book in your local
library catalog. The trick is to use the same idea, but inside of Plone
with an RSS feed that displays current bestsellers or other book-related
stuff where there's an ISBN included.

Here's the sort of python script I need, to the best of my knowledge,
though the first function I can't use (it checks against an Amazon
Wishlist--I don't want anything to be dependent on Amazon or a
particular browser). Jon Udell provided it, and he's the one who wrote
the LibraryLookup bookmarklet that does something similar to what I
want:

import amazon, re, urllib2

wishes = amazon.searchByWishlist('BNQ1T3SLPJS7');

def rss( items ):
 return """<rss version="0.91">
<channel>
<title>LibraryLookup reminders</title>
<link>http://www.amazon.com</link>
<description>Remind me when books on my Amazon wishlist become
available at the library</description>
%s
</channel>
</rss> """ % items

def isAvailable ( isbn ):
 url = 'http://ksclib.keene.edu/search/i=%s' % isbn
 page = urllib2.urlopen(url).read()
 return re.search ( 'AVAILABLE', page ) is not None

items = ''

for wish in wishes:
 isbn = wish.Asin
 if (  ( re.match( '\d{7,9}[\d|X]', isbn ) is not None) and
isAvailable(isbn) ):
   items += """
<item>
<title>%s</title>
<link>%s</link>
<description>%s</description>
</item>\n  """ %  ( wish.ProductName, wish.URL, wish.Authors.Author )

output = rss ( items )

name = 'libraryReminders.xml'

f = open(name,'w')
f.write(output)
f.close()
--------------------------------------------------------
So, I need to simplify this script (get rid of the wishlist stuff),
create an external method for it, then figure out how to get the
template in CMFSin to call the external method. I've never done any of
this before (which probably explains why I have a hard time describing
my problem better).

The CMFSin template I need to alter looks like this, and I'm not sure
exactly where or how to call the method:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"
      lang="en-US"
      metal:use-macro="here/main_template/macros/master"
      i18n:domain="plone">

  <metal:block fill-slot="base">
    <tal:block tal:define="dummy python:request.set('disable_border',
1)"
               tal:replace="nothing">
    Disable the tabs
    </tal:block>
  </metal:block>

  <div metal:fill-slot="main"
       tal:define="true python: 1;
                   false python: 0;
                   verbose python: 1;
		   sin here/sin_tool;
                   m request/synmap;
		   results python:sin.sin(m);
                   Batch python:modules['Products.CMFPlone'].Batch;
                   b_start python:request.get('b_start',0);
		   ">

        <div class="contentHeader">
        <h1 tal:content="m">Title or id</h1>
        </div>

	<tal:block tal:define="batch python:Batch(results, 15,
int(b_start), orphan=1)">

        <!-- Navigation -->
        <div metal:use-macro="here/batch_macros/macros/navigation" />

	<dl tal:repeat="obj batch">
		<dt><a href="#"  tal:attributes="href obj/link"
tal:content="structure obj/title"/>&nbsp; <span tal:condition="python:
obj.get('date') or nothing" tal:content="python: (obj['date'])"/></dt>
		<dd><span tal:condition="python: verbose and
obj.get('description') or nothing" tal:replace="structure
obj/description"/>&nbsp;
                </dd>
	</dl>

        <!-- Navigation -->
        <div metal:use-macro="here/batch_macros/macros/navigation" />
	</tal:block>
        <p tal:condition="not: results"
i18n:translate="description_no_items_in_feed">
           There are currently no items in this feed.
        </p>
    </div>
</html>




-----Original Message-----
From: Chris Withers [mailto:chris at simplistix.co.uk] 
Sent: Monday, April 04, 2005 6:12 AM
To: MILLER Eva
Cc: zope at zope.org
Subject: Re: [Zope] RSS feed: post-processing?


Sorry Eva,

You'll need to explain your problem more succintly for people to be able

to help. If you really do need to scrape the urls from the text, then a 
combination of python's xml handling and regular expressions is probably

what you're after, best done in an external method and not a python 
script...

cheers,

Chris

MILLER Eva wrote:

> Hello,
> 
> I've been puzzling over something but can't figure out a solution. I
> have an RSS feed providing the content behind all the links on this  
> page: http://demo.plinkit.org/interestsideas/goodreads/booklists.
> 
> There's a nice bookmarklet tool in the world called LibraryLookup that
> lets you check whether a book you find on Amazon or something is in  
> your library's catalog by scraping up the ISBN and launching an ISBN  
> catalog search. It's a javascript, really. I thought I would adapt
this
> 
> to create a little add-on for the stuff the bestsellers RSS brings 
> back
> 
> to my site. What I need to do is pluck out the ISBNs in the links on a
> page like this one:  
>
http://demo.plinkit.org/interestsideas/goodreads/sinList?synmap=Hardcove
> rFiction
> 
> The ISBNs are all in the URLs for the book titles
> ("isbn=Some10digitNumberHere"). How would I look for a piece of text
in
> 
> that shape, i.e., isbn=5893193390, then, if it's there, copy and paste
> that piece of information into the LibraryLookup javascript I have.
The
> 
> end result should be that, if there's an ISBN in a feed result, an 
> extra link
> appears for each entry that says something like "Check the catalog,"  
> which you can click to look that book up in your own library's
catalog.
> 
> I've been staring at the template that formats the RSS feed to figure
> out whether any TAL expression would work for this. I've been playing

> with a short Python script, then wondering how to call it within that

> template, but I think I have to use regular expressions to do it.
> 
> I'm sorry to be so lost on this, but I guess I am. I'd love to do
> something cool like this for our little Plinkit libraries. Can anyone

> help? I'll take anything from a broad strategy to actual code snippets

> (I'm a terrible programmer but a good librarian).
> 
> Thanks
> Eva the Librarian
> 
> 
> 
> ----------------------------------------------------------------------
> --
> 
> _______________________________________________
> Zope maillist  -  Zope at zope.org 
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk


More information about the Zope mailing list