Implement toogling articles starred.

sqlite
VikingKong 3 years ago
parent b1e382ad89
commit cef3a76618

@ -50,12 +50,18 @@ class Fetcher:
return False
def toggleArticleStatus(self, articleId, is_read):
if is_read == 0:
return self.toggleArticleTag(articleId, is_read, "user/-/state/com.google/read")
def toggleArticleStarred(self, articleId, is_favorite):
return self.toggleArticleTag(articleId, is_favorite, "user/-/state/com.google/starred")
def toggleArticleTag(self, articleId, is_set, tag):
if is_set == 0:
tag_op = 'r'
else:
tag_op = 'a'
try:
response = httpx.post(self.URL+"/reader/api/0/edit-tag", data={"i": articleId, tag_op: "user/-/state/com.google/read"},
response = httpx.post(self.URL+"/reader/api/0/edit-tag", data={"i": articleId, tag_op: tag},
headers=self.headers)
if response.status_code == 200:
return True

@ -62,6 +62,7 @@ class LeftPane(urwid.ListBox):
if self.isCategoryView:
try:
self.currentCategory = focus_widget.attr_map[None][0]
Utils.writeLog(focus_widget.attr_map)
except BaseException:
self.currentCategory = None
@ -123,7 +124,7 @@ class LeftPane(urwid.ListBox):
return
elif key in ("l", "right"):
try:
if self.isCategoryView:
if self.isCategoryView and self.currentCategory != "Favorites":
self.isCategoryView = False
focus_widget, idx = self.get_focus()
self.categoryPosition = idx
@ -230,6 +231,21 @@ class RightPane(urwid.ListBox):
except BaseException:
pass
return
elif key in ("f"):
Utils.writeLog(tui.feedView.currentCategory)
if self.isList is True:
article_widget, article_idx = self.get_focus()
articleId = article_widget.attr_map[None]
tui.cache.toggleArticleStarred(articleId)
tui.categories = tui.cache.getCategories(tui.show_read)
item_widget, item_idx = tui.feedView.get_focus()
if tui.feedView.isCategoryView:
tui.feedView.fill(tui.categories, tui.feedView.isCategoryView)
Utils.writeLog(tui.feedView.currentCategory)
tui.feedView.set_focus(item_idx)
if item_idx == 0:
tui.feedView.setCategoryArticles(('Favorites', 'Favorites'))
elif key in ("r"):
if self.isList is True:
feeds = []
@ -274,7 +290,6 @@ class RightPane(urwid.ListBox):
focus_widget, idx = self.get_focus()
self.articlePosition = idx
articleId = focus_widget.attr_map[None]
Utils.writeLog(tui.feedView.currentCategory)
self.article = Render(*tui.cache.getArticle(articleId, tui.feedView.currentCategory == "Favorites"),
tui.cache.getArticleLinks(articleId))
walker = urwid.SimpleListWalker([urwid.Text(self.article.firstPage)])

@ -119,6 +119,28 @@ class Cache:
else:
self.conn.rollback()
def toggleArticleStarred(self, id):
inc = 0
cur = self.conn.cursor()
is_favorite = 1
cur.execute("""select id from favorites where id = ?""", (id,))
if bool(cur.fetchone()):
cur.execute("""delete from favorites where id = ?""", (id,))
is_favorite = 0
inc = -1
else:
inc = 1
cur.execute("""select title, timestamp, date, content, url from articles where id = ?""", (id,))
title, timestamp, date, content, url = cur.fetchone()
cur.execute("""insert into favorites(id, title, timestamp, date, content, url) values(:id, :title, :timestamp, :date
,:content, :url)""", {"id": id, "title": title, "timestamp": timestamp, "date": date, "content": content,
"url": url})
cur.execute("""update categories set unread_count = unread_count + ? where id = ?""", (inc, "Favorites",))
if self.api.toggleArticleStarred(id, is_favorite):
self.conn.commit()
else:
self.conn.rollback()
def getArticleLinks(self, id):
cur = self.conn.cursor()
cur.execute("""select url from links where id = ?""", (id,))
@ -157,7 +179,7 @@ class Cache:
cur.execute(statement, (category_id,))
return cur.fetchall()
def refresh(self): # noqa
def refresh(self): # noqa
timestamps = {}
cur = self.conn.cursor()
cur.execute("""select id, timestamp from categories""")

Loading…
Cancel
Save