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
33 CONFIGDIR="/home/user/.feedingit/"
36 return md5.new(string).hexdigest()
39 # Contains all the info about a single feed (articles, ...), and expose the data
40 def __init__(self, name, url):
44 self.updateTime = "Never"
45 #self.feed=feedparser.parse(url)
48 tmp=feedparser.parse(self.url)
49 if len(tmp["entries"])>0:
51 self.updateTime = time.asctime()
52 file = open(CONFIGDIR+getId(self.name), "w")
53 pickle.dump(self, file )
56 def getUpdateTime(self):
57 return self.updateTime
61 return self.feed["entries"]
65 def getItem(self, index):
67 return self.feed["entries"][index]
71 def getArticle(self, index):
72 entry = self.feed["entries"][index]
73 text = "<h4><a href=\"" + entry["link"] + "\">" + entry["title"] + "</a></h4>"
74 text = text + "<small><i>Date: " + time.strftime("%a, %d %b %Y %H:%M:%S",entry["updated_parsed"]) + "</i></small>"
75 text = text + "<BR />"
76 text = text + entry["summary"]
80 # Lists all the feeds in a dictionary, and expose the data
82 def updateFeeds(self):
83 for key in self.listOfFeeds.keys():
84 self.feeds[key].updateFeed()
86 def getFeed(self, key):
87 return self.feeds[key]
89 def getFeedUpdateTime(self, key):
90 return self.feeds[key].getUpdateTime()
92 def getFeedTitle(self, key):
93 return self.listOfFeeds[key]["title"]
95 def getFeedUrl(self, key):
96 return self.listOfFeeds[key]["url"]
98 def getListOfFeeds(self):
99 return self.listOfFeeds.keys()
101 def addFeed(self, title, url):
102 self.listOfFeeds[getId(title)] = {"title":title, "url":url}
104 self.feeds[getId(title)] = Feed(title, url)
106 def saveConfig(self):
107 file = open(CONFIGDIR+"feeds.pickle", "w")
108 pickle.dump(self.listOfFeeds, file)
113 if isfile(CONFIGDIR+"feeds.pickle"):
114 file = open(CONFIGDIR+"feeds.pickle")
115 self.listOfFeeds = pickle.load(file)
118 self.listOfFeeds = {getId("Slashdot"):{"title":"Slashdot", "url":"http://rss.slashdot.org/Slashdot/slashdot"}, }
119 for key in self.listOfFeeds.keys():
120 if isfile(CONFIGDIR+key):
121 file = open(CONFIGDIR+key)
122 self.feeds[key] = pickle.load(file)
125 self.feeds[key] = Feed(self.listOfFeeds[key]["title"], self.listOfFeeds[key]["url"])