no existance checks

This commit is contained in:
josch 2012-07-01 14:29:04 +02:00
parent b55097e8c3
commit 1c80c2d97d
2 changed files with 23 additions and 20 deletions

View file

@ -514,11 +514,11 @@ class EntryTree(Gtk.TreeView):
self.feedurl = None self.feedurl = None
for feedurl in config: for feedurl in config:
if self.feeddb.feed_exists(feedurl): if self.feeddb.get_feed(feedurl):
self.update(feedurl) self.update(feedurl)
def display(self, feedurl): def display(self, feedurl):
if not feedurl or not self.feeddb.feed_exists(feedurl): if not feedurl or not self.feeddb.get_feed(feedurl):
self.set_model(self.empty_model) self.set_model(self.empty_model)
self.feedurl = None self.feedurl = None
else: else:
@ -605,8 +605,8 @@ class FeedTree(Gtk.TreeView):
for category, feeds in categories.items(): for category, feeds in categories.items():
it = self.model.append(None, [None, category, folder_icon, None]) it = self.model.append(None, [None, category, folder_icon, None])
for feedurl in feeds: for feedurl in feeds:
if self.feeddb.feed_exists(feedurl): feed = self.feeddb.get_feed(feedurl)
feed = self.feeddb.get_feed(feedurl) if feed:
feed_icon = feed.get('favicon') feed_icon = feed.get('favicon')
if feed_icon: if feed_icon:
feed_icon = pixbuf_new_from_file_in_memory(feed_icon, (16, 16)) feed_icon = pixbuf_new_from_file_in_memory(feed_icon, (16, 16))
@ -822,7 +822,7 @@ class FeedTree(Gtk.TreeView):
# TODO: display error "cannot identify feeditems" # TODO: display error "cannot identify feeditems"
break break
if self.feeddb.entry_exists(feedurl, itemid): if self.feeddb.get_entry(feedurl, itemid):
# already exists # already exists
continue continue

View file

@ -54,18 +54,27 @@ class SQLStorage():
dbcreate(self.conn) dbcreate(self.conn)
def get_feed(self, feed): def get_feed(self, feed):
return dict(zip(('title', 'favicon', 'etag', 'lastmodified', 'unread'), result = self.conn.execute("""SELECT title, favicon, etag, lastmodified, unread FROM feeds WHERE feed=?""", (feed,)).fetchone()
self.conn.execute("""SELECT title, favicon, etag, lastmodified, unread FROM feeds WHERE feed=?""", (feed,)).fetchone())) if result:
return dict(zip(('title', 'favicon', 'etag', 'lastmodified', 'unread'), result))
else:
return dict()
def get_entry(self, feed, entry): def get_entry(self, feed, entry):
return dict(zip(('title', 'content', 'link', 'date', 'unread', 'categories'), result = self.conn.execute("""SELECT title, content, link, date, unread, categories FROM entries WHERE feed=? AND entry=?""", (feed, entry)).fetchone()
self.conn.execute("""SELECT title, content, link, date, unread, categories FROM entries WHERE feed=? AND entry=?""", (feed, entry)).fetchone())) if result:
return dict(zip(('title', 'content', 'link', 'date', 'unread', 'categories'), result))
else:
return dict()
def get_entries_all(self, feed): def get_entries_all(self, feed):
return [dict(zip(('entry', 'title', 'date', 'unread'), content)) result = self.conn.execute(
for content in self.conn.execute(""" """SELECT entry, title, date, unread FROM entries WHERE feed=? ORDER BY date DESC""",
SELECT entry, title, date, unread FROM entries WHERE feed=? ORDER BY date DESC (feed,)).fetchall()
""", (feed,)).fetchall()] if result:
return [dict(zip(('entry', 'title', 'date', 'unread'), c)) for c in result]
else:
return list()
def add_entry(self, feed, entry, values): def add_entry(self, feed, entry, values):
self.conn.execute("""REPLACE INTO entries (feed, entry, title, content, link, date, unread, categories) VALUES (?, ?, ?, ?, ?, ?, ?, ?)""", self.conn.execute("""REPLACE INTO entries (feed, entry, title, content, link, date, unread, categories) VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
@ -74,7 +83,7 @@ class SQLStorage():
def update_feed(self, feed, values): def update_feed(self, feed, values):
self.conn.execute("""UPDATE feeds SET title=?, favicon=?, etag=?, lastmodified=?, unread=? WHERE feed=?""", self.conn.execute("""UPDATE feeds SET title=?, favicon=?, etag=?, lastmodified=?, unread=? WHERE feed=?""",
(values['title'], values['favicon'], values['etag'], values['lastmodified'], values['unread'], feed)) (values['title'], values.get('favicon'), values.get('etag'), values.get('lastmodified'), values['unread'], feed))
self.conn.commit() self.conn.commit()
def set_favicon(self, feed, favicon): def set_favicon(self, feed, favicon):
@ -91,12 +100,6 @@ class SQLStorage():
self.conn.execute("""UPDATE feeds set unread=0 WHERE feed=?""", (feed,)) self.conn.execute("""UPDATE feeds set unread=0 WHERE feed=?""", (feed,))
self.conn.commit() self.conn.commit()
def feed_exists(self, feed):
return self.conn.execute("""SELECT feed FROM feeds WHERE feed=?""", (feed,)).fetchone() is not None
def entry_exists(self, feed, entry):
return self.conn.execute("""SELECT feed FROM entries WHERE feed=? AND entry=?""", (feed,entry)).fetchone() is not None
def close(self): def close(self):
self.conn.close() self.conn.close()