Re: [Tutor] Get variable values [Introduction to Planet RSS news aggregator] (fwd)
Hi, Now, i got into something: http://pastebin.com/873482 I'm already inserting data in MySQL. Just two glitches: 1) This way i can only retrieve information from one blog. The one in the line c = planet.Channel(p, http://blog.gamito.org/rss.php?blogId=1profile=rss20;) How can i retrieve from them all ? 2) I can't get the category and the URL :( The code from __init.py__ and cache.py are here: http://pastebin.com/872998 http://pastebin.com/873004 Any help would be appreciated. Warm Regards, Mário Gamito ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Get variable values [Introduction to Planet RSS news aggregator] (fwd)
On Fri, 2 Feb 2007, Mário Gamito wrote: 1) This way i can only retrieve information from one blog. The one in the line c = planet.Channel(p, http://blog.gamito.org/rss.php?blogId=1profile=rss20;) How can i retrieve from them all ? Hi Mario, Have you tried asking for help from the planet devel list? http://lists.planetplanet.org/mailman/listinfo/devel From what I understand, Planet does it own on-disk caching already: it really does look like you're trying to implement something that Planet already does internally. There's a refactored version of Planet Planet called Planet Venus which may be helpful for you: http://intertwingly.net/code/venus/docs/ I would strongly recommend looking closely at it, as it at least has some docs you can read. 2) I can't get the category and the URL :( We can't tell what you're doing from this end. Please make sure you're showing us what you mean when you run into difficulties --- showing code that demonstrates the problem is usually good.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Get variable values [Introduction to Planet RSS news aggregator] (fwd)
Hi, Danny Yoo wrote: Have you tried asking for help from the planet devel list? Yes, but the list is comfortably numb :( From what I understand, Planet does it own on-disk caching already: it really does look like you're trying to implement something that Planet already does internally. Yes it does. But I want to put the feeds data into the database to make pagination (as is, in planetplanet once a new article arrives, the last goes to the oblivion), subscribe only certain categories from a blog, censor some nasty article, etc. Planetplanet doesn't have nothing of this. There's a refactored version of Planet Planet called Planet Venus which may be helpful for you: Yes, i know, i've already its docs. Regards, Mário Gamito ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Get variable values [Introduction to Planet RSS news aggregator]
Yes, i've read the two docs. But my problem is more related with Python. If you read my previous post with the links to the code, my doubt is how to get the values for url, content, name, etc. Hi Mario, After taking a much closer look at the code you mentioned here: http://pastebin.com/872998 it looks like you're supposed to have a NewsItem in hand. Ok, wait. I think I have a better idea of what you're trying to do. Let me try to dissuade you from doing what you're doing. *grin* There should be no reason for mucking into the definition of Planet's implementation in order to make it do what you want: you should be able to just treat Planet as a library, and use it to do what you want. You should almost certainly not touch the internals of get_content(), if I understand what you're trying to do: that's private to the implementation of Planet and a very bad approach toward code reuse. Rather than hack at NewsItem.get_content() to get it to insert into a database, it's probably a lot better to not modify Planet, but rather write new programs that use Planet. Respect the library and treat it as if it were a resource. If Scott James Remnant and Jeff Waugh take their code at: http://www.planetplanet.org/ and update it, or correct bugs, then you do not want to have to manually update your own code to patch things up the same way. Concretely, if we want to take a feed and print out all the titles, we should not be modify the get_title() method of these news items in a private copy of the Planet library. Rather, we can more simply use Planet as an external library: # import planet import ConfigParser config = ConfigParser.ConfigParser() p = planet.Planet(config) c = planet.Channel(p, http://hashcollision.blogspot.com/feeds/posts/default;) c.update() len(c.items()) 25 # Ok, there are 25 items here. Let's take a look at the titles: ## for item in c: ... print item.title ... latex in summation... heresy debugging test-case new year [text output truncated] ## Let's look at a particular item in the channel. firstItem = c.items()[0] firstItem.title 'how not to write xml' firstItem.id 'tag:blogger.com,1999:blog-18302393.post-116249176169366001' firstItem.link 'http://hashcollision.blogspot.com/2006/11/how-not-to-write-xml.html' firstItem.summary Traceback (most recent call last): File stdin, line 1, in ? File /usr/lib/python2.4/site-packages/planet/cache.py, line 279, in __getattr__ raise AttributeError, key AttributeError: summary Ok, so some things are not defined. That's to be expected. What things are defined for my news item? firstItem.keys() ['updated', 'subtitle', 'title', 'author', 'author_name', 'order', 'content', 'link', 'published', 'date', 'id_hash', 'id'] firstItem.author 'Danny Yoo' (It really is _my_ news item. *wink*) According to the documentation of a NewsItem, you can expect to see the following (usually): # id Channel-unique identifier for this item. id_hash Relatively short, printable cryptographic hash of id dateCorrected UTC-Normalised update time, for sorting. order Order in which items on the same date can be sorted. hidden Item should be hidden (True if exists). title One-line title (*). linkLink to the original format text (*). summary Short first-page summary (*). content Full HTML content. modifiedDate the item claims to have been modified (*). issued Date the item claims to have been issued (*). created Date the item claims to have been created (*). expired Date the item claims to expire (*). author Name of the author (*). publisher Name of the publisher (*). categoryCategory name (*). commentsLink to a page to enter comments (*). license Link to the licence for the content (*). source_name Name of the original source of this item (*). source_link Link to the original source of this item (*). # In able to see help documentation on planet, use the help() function at the prompt: # import planet help(planet) # The documentation on Planet is a bit focused for developers: the authors expect you to already know Python before touching Planet, so you might have some rough going at first. Does this help you get started? Please ask more questions if you
Re: [Tutor] Get variable values [Introduction to Planet RSS news aggregator] (fwd)
-- Forwarded message -- Date: Fri, 02 Feb 2007 00:52:49 + From: [ISO-8859-1] Mário Gamito [EMAIL PROTECTED] To: Danny Yoo [EMAIL PROTECTED] Subject: Re: [Tutor] Get variable values [Introduction to Planet RSS news aggregator] 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, db=planet_geek) cursor = db.cursor() config = ConfigParser.ConfigParser() p = planet.Planet(config) c = planet.Channel(p, http://blog.gamito.org/rss.php?blogId=1profile=rss20;) c.update() 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 list) which means that the variable item.title is not recognized as a variable. Any ideas ? Warm Regards, Mário Gamito ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor