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 from os.path import isfile
27 from os.path import isdir
31 CONFIGDIR="/home/user/.feedingit/"
34 return md5.new(string).hexdigest()
37 # Contains all the info about a single feed (articles, ...), and expose the data
38 def __init__(self, name, url):
42 self.updateTime = "Never"
43 #self.feed=feedparser.parse(url)
46 self.feed=feedparser.parse(self.url)
47 self.updateTime = time.asctime()
48 file = open(CONFIGDIR+getId(self.name), "w")
49 pickle.dump(self, file )
52 def getUpdateTime(self):
53 return self.updateTime
57 return self.feed["entries"]
61 def getItem(self, index):
63 return self.feed["entries"][index]
67 def getArticle(self, index):
68 entry = self.feed["entries"][index]
69 text = "<h4><a href=\"" + entry["link"] + "\">" + entry["title"] + "</a></h4>"
70 text = text + "<small><i>Date: " + time.strftime("%a, %d %b %Y %H:%M:%S",entry["updated_parsed"]) + "</i></small>"
71 text = text + "<BR />"
72 text = text + entry["summary"]
76 # Lists all the feeds in a dictionary, and expose the data
78 def updateFeeds(self):
79 for key in self.listOfFeeds.keys():
80 self.feeds[key].updateFeed()
82 def getFeed(self, key):
83 return self.feeds[key]
85 def getFeedUpdateTime(self, key):
86 return self.feeds[key].getUpdateTime()
88 def getFeedTitle(self, key):
89 return self.listOfFeeds[key]["title"]
91 def getFeedUrl(self, key):
92 return self.listOfFeeds[key]["url"]
94 def getListOfFeeds(self):
95 return self.listOfFeeds.keys()
97 def addFeed(self, title, url):
98 self.listOfFeeds[getId(title)] = {"title":title, "url":url}
100 self.feeds[getId(title)] = Feed(title, url)
102 def saveConfig(self):
103 file = open(CONFIGDIR+"feeds.pickle", "w")
104 pickle.dump(self.listOfFeeds, file)
109 if isfile(CONFIGDIR+"feeds.pickle"):
110 file = open(CONFIGDIR+"feeds.pickle")
111 self.listOfFeeds = pickle.load(file)
114 self.listOfFeeds = {getId("Slashdot"):{"title":"Slashdot", "url":"http://rss.slashdot.org/Slashdot/slashdot"}, }
115 for key in self.listOfFeeds.keys():
116 if isfile(CONFIGDIR+key):
117 file = open(CONFIGDIR+key)
118 self.feeds[key] = pickle.load(file)
121 self.feeds[key] = Feed(self.listOfFeeds[key]["title"], self.listOfFeeds[key]["url"])