1 #!/usr/bin/env python2.5
4 # Copyright (c) 2007-2008 INdT.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # ============================================================================
21 # Author : Yves Marcoz
23 # Description : PyGtk Example
24 # ============================================================================
26 CONFIGDIR="/home/user/.feedingit/"
29 return md5.new(string).hexdigest()
32 # Contains all the info about a single feed (articles, ...), and expose the data
33 def __init__(self, name, url):
37 self.updateTime = "Never"
38 #self.feed=feedparser.parse(url)
41 self.feed=feedparser.parse(self.url)
42 self.updateTime = time.asctime()
43 file = open(CONFIGDIR+getId(self.name), "w")
44 pickle.dump(self, file )
47 def getUpdateTime(self):
48 return self.updateTime
52 return self.feed["entries"]
56 def getItem(self, index):
58 return self.feed["entries"][index]
62 def getArticle(self, index):
63 entry = self.feed["entries"][index]
64 text = "<h4><a href=\"" + entry["link"] + "\">" + entry["title"] + "</a></h4>"
65 text = text + "<small><i>Date: " + time.strftime("%a, %d %b %Y %H:%M:%S",entry["updated_parsed"]) + "</i></small>"
66 text = text + "<BR />"
67 text = text + entry["summary"]
71 # Lists all the feeds in a dictionary, and expose the data
73 def updateFeeds(self):
74 for key in self.listOfFeeds.keys():
75 self.feeds[key].updateFeed()
77 def getFeed(self, key):
78 return self.feeds[key]
80 def getFeedUpdateTime(self, key):
81 return self.feeds[key].getUpdateTime()
83 def getFeedTitle(self, key):
84 return self.listOfFeeds[key]["title"]
86 def getFeedUrl(self, key):
87 return self.listOfFeeds[key]["url"]
89 def getListOfFeeds(self):
90 return self.listOfFeeds.keys()
92 def addFeed(self, title, url):
93 self.listOfFeeds[getId(title)] = {"title":title, "url":url}
95 self.feeds[getId(title)] = Feed(title, url)
98 file = open(CONFIGDIR+"feeds.pickle", "w")
99 pickle.dump(self.listOfFeeds, file)
104 if isfile(CONFIGDIR+"feeds.pickle"):
105 file = open(CONFIGDIR+"feeds.pickle")
106 self.listOfFeeds = pickle.load(file)
109 self.listOfFeeds = {getId("Slashdot"):{"title":"Slashdot", "url":"http://rss.slashdot.org/Slashdot/slashdot"}, }
110 for key in self.listOfFeeds.keys():
111 if isfile(CONFIGDIR+key):
112 file = open(CONFIGDIR+key)
113 self.feeds[key] = pickle.load(file)
116 self.feeds[key] = Feed(self.listOfFeeds[key]["title"], self.listOfFeeds[key]["url"])