RSS feed parser
Florian.Lindner at xgm.de
Wed Apr 4 12:45:50 CEST 2007
irstas at gmail.com wrote:
> On Apr 2, 10:20 pm, Florian Lindner <Florian.Lind... at xgm.de> wrote:
>> Some of the question I have but found answered nowhere:
>> I have a feedparser object that was created from a string. How can I
>> trigger a update (from a new string) but the feedparser should treat the
>> new string like the same feed (thus setting feed.updated etc.).
> Hmm. Do you mean that the feed object should stay the same? Like the
> difference between "a = [1,2,3]; a = [1,2,3]+" and "a = [1,2,3];
> a.append(4)"? I glanced at the parse function in the source code and
> it looks like it's not directly possible. You could modify it so that
> the "result" dictionary is optionally given as an argument, so when
> updating you'd do: feedparser.parse(string, oldFeed). You'd also have
> to clear the oldFeed object before update.
> But you might also be able to solve the problem by using an additional
> layer of indirection. Instead of passing around the "feed" object,
> you'd pass around a proxy object like this:
> class Empty: pass
> proxy = Empty()
> proxy.feed = feedparser.parse(string)
> proxy.feed = feedparser.parse(string2)
> useStoredProxy() #this would use the updated feed through the proxy
> Then just use proxy.feed.updated everywhere instead of directly
> feed.updated. A smarter proxy would automatically translate
> proxy.updated into proxy.feed.updated so usage would stay as simple as
> without the proxy. Doing this is quite easy in Python (search for
> __getattr__ examples).
I already use something like that (with __getattr__). The problem is that
with this way there is still a new feed object created everytime a new
string needs to be passed to.
But since I want to use use the updated_parsed etc. function it's not
possible that each time the feed is parsed a new object is created (the
update times will always be the time of the last parsing).
More information about the Python-list