[Tutor] Get variable values [Introduction to Planet RSS news aggregator] (fwd)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Feb 2 04:55:33 CET 2007

---------- Forwarded message ----------
Date: Fri, 02 Feb 2007 00:52:49 +0000
From: "[ISO-8859-1] Mário Gamito" <gamito at gmail.com>
To: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] Get variable values  [Introduction to Planet RSS news

Hi Danny,

Thank you for your insightful info.

Now i'm getting somewhere.

I've made this mysql.py teste script:

import planet
import ConfigParser
import MySQLdb

db = MySQLdb.connect(host="localhost", user="planet", passwd="secret", 
cursor = db.cursor()

config = ConfigParser.ConfigParser()
p = planet.Planet(config)
c = planet.Channel(p, "http://blog.gamito.org/rss.php?blogId=1&profile=rss20")
print len(c.items())

for item in c:
    print item.title
    cursor.execute("INSERT INTO blog_posts (title) VALUES (item.title)")
    print item.content

it prints the info from the feeds to the screen, but get an error from MySQL:
"File "sql.py", line 16, in ?
     cursor.execute("INSERT INTO blog_posts (title) VALUES (item.title)")
   File "/usr/local/lib/python2.4/site-packages/MySQLdb/cursors.py", line 163, 
in execute
     self.errorhandler(self, exc, value)
   File "/usr/local/lib/python2.4/site-packages/MySQLdb/connections.py", line 
35, in defaulterrorhandler
     raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1109, "Unknown table 'item' in field 

which means that the variable item.title is not recognized as a variable.

Any ideas ?

Warm Regards,
Mário Gamito

More information about the Tutor mailing list