from rss import Listing
from opml import GetOpmlData, ExportOpmlData
+from urllib2 import install_opener, build_opener
+
from socket import setdefaulttimeout
timeout = 5
setdefaulttimeout(timeout)
key_lock = get_lock(self.key)
if key_lock != None:
if use_proxy:
- from urllib2 import install_opener, build_opener
- install_opener(build_opener(proxy))
self.listing.updateFeed(self.key, self.config.getExpiry(), proxy=proxy, imageCache=self.config.getImageCache() )
else:
self.listing.updateFeed(self.key, self.config.getExpiry(), imageCache=self.config.getImageCache() )
self.config = config
self.current = 0
self.single = single
+ (use_proxy, proxy) = self.config.getProxy()
+ if use_proxy:
+ opener = build_opener(proxy)
+ opener.addheaders = [('User-agent', 'Mozilla/5.0 (compatible; Maemo 5;) FeedingIt 0.6.1')]
+ install_opener(opener)
+ else:
+ opener = build_opener()
+ opener.addheaders = [('User-agent', 'Mozilla/5.0 (compatible; Maemo 5;) FeedingIt 0.6.1')]
+ install_opener(opener)
if self.total>0:
self.set_text("Updating...")
#self.set_title(feed.getTitle(id))
self.set_title(self.listing.getFeedTitle(key))
self.config = config
+ self.set_for_removal = False
# Init the article display
#if self.config.getWebkitSupport():
button.connect("clicked", self._signal_link_clicked, self.feed.getExternalLink(self.id))
menu.append(button)
- button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
- button.set_label("Add to Archived Articles")
- button.connect("clicked", self.archive_button)
+ if key == "ArchivedArticles":
+ button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+ button.set_label("Remove from Archived Articles")
+ button.connect("clicked", self.remove_archive_button)
+ else:
+ button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+ button.set_label("Add to Archived Articles")
+ button.connect("clicked", self.archive_button)
menu.append(button)
self.set_app_menu(menu)
def destroyWindow(self, *args):
self.disconnect(self.destroyId)
- self.emit("article-closed", self.id)
+ if self.set_for_removal:
+ self.emit("article-deleted", self.id)
+ else:
+ self.emit("article-closed", self.id)
#self.imageDownloader.stopAll()
self.destroy()
# Call the listing.addArchivedArticle
self.listing.addArchivedArticle(self.key, self.id)
+ def remove_archive_button(self, *widget):
+ self.set_for_removal = True
+
#def reloadArticle(self, *widget):
# if threading.activeCount() > 1:
# Image thread are still running, come back in a bit
class DisplayFeed(hildon.StackableWindow):
- def __init__(self, listing, feed, title, key, config):
+ def __init__(self, listing, feed, title, key, config, updateDbusHandler):
hildon.StackableWindow.__init__(self)
self.listing = listing
self.feed = feed
self.set_title(title)
self.key=key
self.config = config
+ self.updateDbusHandler = updateDbusHandler
self.downloadDialog = False
- self.listing.setCurrentlyDisplayedFeed(self.key)
+ #self.listing.setCurrentlyDisplayedFeed(self.key)
self.disp = False
button.set_label("Mark All As Read")
button.connect("clicked", self.buttonReadAllClicked)
menu.append(button)
+
+ if key=="ArchivedArticles":
+ button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+ button.set_label("Purge Read Articles")
+ button.connect("clicked", self.buttonPurgeArticles)
+ menu.append(button)
+
self.set_app_menu(menu)
menu.show_all()
self.connect("destroy", self.destroyWindow)
def destroyWindow(self, *args):
- self.feed.saveUnread(CONFIGDIR)
+ #self.feed.saveUnread(CONFIGDIR)
+ gobject.idle_add(self.feed.saveUnread, CONFIGDIR)
self.listing.updateUnread(self.key, self.feed.getNumberOfUnreadItems())
self.emit("feed-closed", self.key)
self.destroy()
#gobject.idle_add(self.feed.saveFeed, CONFIGDIR)
- self.listing.closeCurrentlyDisplayedFeed()
+ #self.listing.closeCurrentlyDisplayedFeed()
def displayFeed(self):
self.vboxFeed = gtk.VBox(False, 10)
self.disp.show_all()
self.ids = []
+ if self.key == "ArchivedArticles":
+ self.ids.append(self.disp.connect("article-deleted", self.onArticleDeleted))
self.ids.append(self.disp.connect("article-closed", self.onArticleClosed))
self.ids.append(self.disp.connect("article-next", self.nextArticle))
self.ids.append(self.disp.connect("article-previous", self.previousArticle))
+ def buttonPurgeArticles(self, *widget):
+ self.clear()
+ self.feed.purgeReadArticles()
+ self.feed.saveUnread(CONFIGDIR)
+ self.feed.saveFeed(CONFIGDIR)
+ self.displayFeed()
+
def destroyArticle(self, handle):
handle.destroyWindow()
label.modify_font(FontDescription(self.config.getReadFont()))
label.modify_fg(gtk.STATE_NORMAL, read_color) # gtk.gdk.color_parse("white"))
self.buttons[index].show()
+
+ def onArticleDeleted(self, object, index):
+ self.clear()
+ self.feed.removeArticle(index)
+ self.feed.saveUnread(CONFIGDIR)
+ self.feed.saveFeed(CONFIGDIR)
+ self.displayFeed()
def button_update_clicked(self, button):
#bar = DownloadBar(self, self.listing, [self.key,], self.config )
except:
# If feed_lock doesn't exist, we can open the feed, else we do nothing
self.feed_lock = get_lock(key)
- self.disp = DisplayFeed(self.listing, self.listing.getFeed(key), self.listing.getFeedTitle(key), key, self.config)
+ self.disp = DisplayFeed(self.listing, self.listing.getFeed(key), self.listing.getFeedTitle(key), key, self.config, self.updateDbusHandler)
self.disp.connect("feed-closed", self.onFeedClosed)
def onFeedClosed(self, object, key):
+ #self.listing.saveConfig()
+ #del self.feed_lock
+ gobject.idle_add(self.onFeedClosedTimeout)
+ self.refreshList()
+ #self.updateDbusHandler.ArticleCountUpdated()
+
+ def onFeedClosedTimeout(self):
self.listing.saveConfig()
del self.feed_lock
- self.refreshList()
self.updateDbusHandler.ArticleCountUpdated()
def run(self):
# Need to check for internet connection
# If no internet connection, try again in 10 minutes:
# gobject.timeout_add(int(5*3600000), self.automaticUpdate)
+ file = open("/home/user/.feedingit/feedingit_widget.log", "a")
+ from time import localtime, strftime
+ file.write("App: %s\n" % strftime("%a, %d %b %Y %H:%M:%S +0000", localtime()))
+ file.close()
self.button_update_clicked(None, None)
return True
if __name__ == "__main__":
gobject.signal_new("feed-closed", DisplayFeed, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
gobject.signal_new("article-closed", DisplayArticle, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
+ gobject.signal_new("article-deleted", DisplayArticle, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
gobject.signal_new("article-next", DisplayArticle, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
gobject.signal_new("article-previous", DisplayArticle, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
gobject.signal_new("download-done", DownloadBar, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
import time
import urllib2
from BeautifulSoup import BeautifulSoup
-from urlparse import urlparse
+from urlparse import urljoin
#CONFIGDIR="/home/user/.feedingit/"
filename = self.configdir+key+".d/"+getId(url)
if not isfile(filename):
try:
- if url.startswith("http"):
- f = urllib2.urlopen(url)
- else:
- f = urllib2.urlopen(baseurl+"/"+url)
+ #if url.startswith("http"):
+ # f = urllib2.urlopen(url)
+ #else:
+ f = urllib2.urlopen(urljoin(baseurl,url))
outf = open(filename, "w")
outf.write(f.read())
f.close()
outf.close()
except:
- print "Could not download" + url
+ print "Could not download " + url
+ else:
+ open(filename,"a").close() # "Touch" the file
if filename in self.images:
self.images[filename] += 1
else:
if not id in self.ids:
soup = BeautifulSoup(self.getArticle(tmpEntry)) #tmpEntry["content"])
images = soup('img')
- baseurl = ''.join(urlparse(tmpEntry["link"])[:-1])
+ baseurl = tmpEntry["link"]
if imageCache:
for img in images:
try:
img['src']=filename
tmpEntry["images"].append(filename)
except:
- print "Error downloading image %s" %img
+ print "Error downloading image %s" % img
tmpEntry["contentLink"] = configdir+self.uniqueId+".d/"+id+".html"
file = open(tmpEntry["contentLink"], "w")
file.write(soup.prettify())
self.readItems[id] = False
if self.readItems[id]==False:
tmpUnread = tmpUnread + 1
+ keys = self.readItems.keys()
+ for id in keys:
+ if not id in self.ids:
+ del self.readItems[id]
del tmp
self.countUnread = tmpUnread
self.updateTime = time.asctime()
f.close()
soup = BeautifulSoup(html)
images = soup('img')
- baseurl = ''.join(urlparse(entry["link"])[:-1])
+ baseurl = entry["link"]
for img in images:
filename = self.imageHandler.addImage(self.uniqueId, baseurl, img['src'])
- #filename = configdir+self.uniqueId+".d/"+getId(img['src'])
- #if not isfile(filename):
- # try:
- # if img['src'].startswith("http"):
- # f = urllib2.urlopen(img['src'])
- # else:
- # f = urllib2.urlopen(baseurl+"/"+img['src'])
- # #print baseurl+"/"+img['src']
- # print filename
- # outf = open(filename, "w")
- # outf.write(f.read())
- # f.close()
- # outf.close()
- # except:
- # print "Could not download" + img['src']
img['src']=filename
entry["images"].append(filename)
entry["contentLink"] = configdir+self.uniqueId+".d/"+id+".html"
self.setEntryUnread(id)
#except:
# pass
- currentTime = time.time()
- expiry = float(expiryTime) * 3600
- if currentTime - entry["time"] > expiry:
- if self.isEntryRead(id):
- self.removeEntry(id)
- else:
- if currentTime - entry["time"] > 2*expiry:
- self.removeEntry(id)
+ #currentTime = time.time()
+ #expiry = float(expiryTime) * 3600
+ #if currentTime - entry["time"] > expiry:
+ # if self.isEntryRead(id):
+ # self.removeEntry(id)
+ # else:
+ # if currentTime - entry["time"] > 2*expiry:
+ # self.removeEntry(id)
self.updateTime = time.asctime()
self.saveFeed(configdir)
+
+ def purgeReadArticles(self):
+ ids = self.getIds()
+ for id in ids:
+ entry = self.entries[id]
+ if self.isEntryRead(id):
+ self.removeEntry(id)
+
+ def removeArticle(self, id):
+ self.removeEntry(id)
def getArticle(self, index):
self.setEntryRead(index)
self.sortedKeys.remove("font")
self.sortedKeys.sort(key=lambda obj: self.getFeedTitle(obj))
list = self.sortedKeys[:]
- self.closeCurrentlyDisplayedFeed()
+ #self.closeCurrentlyDisplayedFeed()
def addArchivedArticle(self, key, index):
feed = self.getFeed(key)
index2 = (index+1)%len(self.sortedKeys)
self.sortedKeys[index] = self.sortedKeys[index2]
self.sortedKeys[index2] = key
-
- def setCurrentlyDisplayedFeed(self, key):
- self.currentlyDisplayedFeed = key
- def closeCurrentlyDisplayedFeed(self):
- self.currentlyDisplayedFeed = False
- def getCurrentlyDisplayedFeed(self):
- return self.currentlyDisplayedFeed
if __name__ == "__main__":
listing = Listing('/home/user/.feedingit/')