Separated helper classes into rss.py. Added test.py with QT gui
authorYves Marcoz <ymarcoz@stromgarde.(none)>
Tue, 29 Dec 2009 23:55:11 +0000 (15:55 -0800)
committerYves Marcoz <ymarcoz@stromgarde.(none)>
Tue, 29 Dec 2009 23:55:11 +0000 (15:55 -0800)
src/FeedingIt.py
src/rss.py [new file with mode: 0644]
src/test.py

index eaef9e5..928c4a3 100644 (file)
@@ -34,101 +34,9 @@ import pickle
 from os.path import isfile, isdir
 from os import mkdir
 import md5
-import sys
+import sys   
 
-CONFIGDIR="/home/user/.feedingit/"
-
-def getId(string):
-    return md5.new(string).hexdigest()
-
-class Feed:
-    # Contains all the info about a single feed (articles, ...), and expose the data
-    def __init__(self, name, url):
-        self.feed = []
-        self.name = name
-        self.url = url
-        self.updateTime = "Never"
-        #self.feed=feedparser.parse(url)
-    
-    def updateFeed(self):
-        self.feed=feedparser.parse(self.url)
-        self.updateTime = time.asctime()
-        file = open(CONFIGDIR+getId(self.name), "w")
-        pickle.dump(self, file )
-        file.close()
-    
-    def getUpdateTime(self):
-        return self.updateTime
-    
-    def getEntries(self):
-        try:
-            return self.feed["entries"]
-        except:
-            return []
-    
-    def getItem(self, index):
-        try:
-            return self.feed["entries"][index]
-        except:
-            return []
-    
-    def getArticle(self, index):
-        entry = self.feed["entries"][index]
-        text = "<h4><a href=\"" + entry["link"] + "\">" + entry["title"] + "</a></h4>"
-        text = text + "<small><i>Date: " + time.strftime("%a, %d %b %Y %H:%M:%S",entry["updated_parsed"]) + "</i></small>"
-        text = text + "<BR />"
-        text = text + entry["summary"]
-        return text    
-    
-class Listing:
-    # Lists all the feeds in a dictionary, and expose the data
-    
-    def updateFeeds(self):
-        for key in self.listOfFeeds.keys():
-            self.feeds[key].updateFeed()
-            
-    def getFeed(self, key):
-        return self.feeds[key]
-    
-    def getFeedUpdateTime(self, key):
-        return self.feeds[key].getUpdateTime()
-   
-    def getFeedTitle(self, key):
-        return self.listOfFeeds[key]["title"]
-    
-    def getFeedUrl(self, key):
-        return self.listOfFeeds[key]["url"]
-    
-    def getListOfFeeds(self):
-        return self.listOfFeeds.keys()
-    
-    def addFeed(self, title, url):
-        self.listOfFeeds[getId(title)] = {"title":title, "url":url}
-        self.saveConfig()
-        self.feeds[getId(title)] = Feed(title, url)
-    
-    def saveConfig(self):
-        file = open(CONFIGDIR+"feeds.pickle", "w")
-        pickle.dump(self.listOfFeeds, file)
-        file.close()
-    
-    def __init__(self):
-        self.feeds = {}
-        if isfile(CONFIGDIR+"feeds.pickle"):
-            file = open(CONFIGDIR+"feeds.pickle")
-            self.listOfFeeds = pickle.load(file)
-            file.close()
-        else:
-            self.listOfFeeds = {getId("Slashdot"):{"title":"Slashdot", "url":"http://rss.slashdot.org/Slashdot/slashdot"}, }
-        for key in self.listOfFeeds.keys():
-            if isfile(CONFIGDIR+key):
-                file = open(CONFIGDIR+key)
-                self.feeds[key] = pickle.load(file)
-                file.close()
-            else:
-                self.feeds[key] = Feed(self.listOfFeeds[key]["title"], self.listOfFeeds[key]["url"])
-        self.saveConfig()
-   
+from rss import *
    
 class AddWidgetWizard(hildon.WizardDialog):
     
diff --git a/src/rss.py b/src/rss.py
new file mode 100644 (file)
index 0000000..48b30e8
--- /dev/null
@@ -0,0 +1,117 @@
+#!/usr/bin/env python2.5
+
+# 
+# Copyright (c) 2007-2008 INdT.
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public License
+#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# ============================================================================
+# Name        : FeedingIt.py
+# Author      : Yves Marcoz
+# Version     : 0.1
+# Description : PyGtk Example 
+# ============================================================================
+
+CONFIGDIR="/home/user/.feedingit/"
+
+def getId(string):
+    return md5.new(string).hexdigest()
+
+class Feed:
+    # Contains all the info about a single feed (articles, ...), and expose the data
+    def __init__(self, name, url):
+        self.feed = []
+        self.name = name
+        self.url = url
+        self.updateTime = "Never"
+        #self.feed=feedparser.parse(url)
+    
+    def updateFeed(self):
+        self.feed=feedparser.parse(self.url)
+        self.updateTime = time.asctime()
+        file = open(CONFIGDIR+getId(self.name), "w")
+        pickle.dump(self, file )
+        file.close()
+    
+    def getUpdateTime(self):
+        return self.updateTime
+    
+    def getEntries(self):
+        try:
+            return self.feed["entries"]
+        except:
+            return []
+    
+    def getItem(self, index):
+        try:
+            return self.feed["entries"][index]
+        except:
+            return []
+    
+    def getArticle(self, index):
+        entry = self.feed["entries"][index]
+        text = "<h4><a href=\"" + entry["link"] + "\">" + entry["title"] + "</a></h4>"
+        text = text + "<small><i>Date: " + time.strftime("%a, %d %b %Y %H:%M:%S",entry["updated_parsed"]) + "</i></small>"
+        text = text + "<BR />"
+        text = text + entry["summary"]
+        return text    
+    
+class Listing:
+    # Lists all the feeds in a dictionary, and expose the data
+    
+    def updateFeeds(self):
+        for key in self.listOfFeeds.keys():
+            self.feeds[key].updateFeed()
+            
+    def getFeed(self, key):
+        return self.feeds[key]
+    
+    def getFeedUpdateTime(self, key):
+        return self.feeds[key].getUpdateTime()
+   
+    def getFeedTitle(self, key):
+        return self.listOfFeeds[key]["title"]
+    
+    def getFeedUrl(self, key):
+        return self.listOfFeeds[key]["url"]
+    
+    def getListOfFeeds(self):
+        return self.listOfFeeds.keys()
+    
+    def addFeed(self, title, url):
+        self.listOfFeeds[getId(title)] = {"title":title, "url":url}
+        self.saveConfig()
+        self.feeds[getId(title)] = Feed(title, url)
+    
+    def saveConfig(self):
+        file = open(CONFIGDIR+"feeds.pickle", "w")
+        pickle.dump(self.listOfFeeds, file)
+        file.close()
+    
+    def __init__(self):
+        self.feeds = {}
+        if isfile(CONFIGDIR+"feeds.pickle"):
+            file = open(CONFIGDIR+"feeds.pickle")
+            self.listOfFeeds = pickle.load(file)
+            file.close()
+        else:
+            self.listOfFeeds = {getId("Slashdot"):{"title":"Slashdot", "url":"http://rss.slashdot.org/Slashdot/slashdot"}, }
+        for key in self.listOfFeeds.keys():
+            if isfile(CONFIGDIR+key):
+                file = open(CONFIGDIR+key)
+                self.feeds[key] = pickle.load(file)
+                file.close()
+            else:
+                self.feeds[key] = Feed(self.listOfFeeds[key]["title"], self.listOfFeeds[key]["url"])
+        self.saveConfig()
\ No newline at end of file
index d627677..1f9fbeb 100644 (file)
@@ -64,13 +64,15 @@ class ListingDisplay(QtGui.QMainWindow):
         #self.add(listWidget)
         self.show()
 
-class RSSReader(QtGui.QMainWindow):    
+class FeedingIt(QtGui.QMainWindow):    
  
     def __init__(self, parent=None):
         QtGui.QMainWindow.__init__(self, parent)
         self.setWindowTitle('Feeding It')
-        self.setGeometry(100,100,300,300)
 
+        exit = QtGui.QAction(None, 'Exit', self)
+        exit.setStatusTip('Exit application')
+        self.connect(exit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))
 
         self.mainWidget=QtGui.QWidget(self) # dummy widget to contain the
                                       # layout manager
@@ -84,7 +86,7 @@ class RSSReader(QtGui.QMainWindow):
         file = menubar.addAction(exitAction)
         
         self.listing=Listing()
-        self.listing.downloadFeeds()
+        self.displayListing() 
         
         listOfFeeds = QtGui.QListWidget(self.mainWidget)
         
@@ -97,13 +99,42 @@ class RSSReader(QtGui.QMainWindow):
         #layout.addWidget(listOfFeeds) 
         #self.setLayout(layout)
  
-if __name__ == '__main__':    
+    def displayListing(self):
+        #try:
+        #    self.window.remove(self.pannableListing)
+        #except:
+        #    pass
+        #self.vboxListing = gtk.VBox(False,10)
+        #self.pannableListing = hildon.PannableArea()
+        #self.pannableListing.add_with_viewport(self.vboxListing)
+
+        for key in self.listing.getListOfFeeds():
+            #button = gtk.Button(item)
+            #button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
+            #                  hildon.BUTTON_ARRANGEMENT_VERTICAL)
+            #button.set_text(self.listing.getFeedTitle(key), self.listing.getFeedUpdateTime(key))
+            #button.set_alignment(0,0,1,1)
+            #button.connect("clicked", self.buttonFeedClicked, self, self.window, key)
+            #self.vboxListing.pack_start(button, expand=False)
+            pass
+        #self.window.add(self.pannableListing)
+        #self.window.show_all()
+        
+if __name__ == '__main__': 
+
+    # Checking the configuration directory does exist
+    if not isdir(CONFIGDIR):
+        try:
+            mkdir(CONFIGDIR)
+        except:
+            print "Error: Can't create configuration directory"
+            sys.exit(1)
  
     #Creating Qt application
     app = QtGui.QApplication(sys.argv)
  
-    myRSSReader = RSSReader()
-    myRSSReader.show()
+    feedingIt = FeedingIt()
+    feedingIt.show()
  
-    #Initing application
+    #Starting the application's main loop
     sys.exit(app.exec_())
\ No newline at end of file