|
|
|
|
@ -4,6 +4,7 @@ import os
|
|
|
|
|
import functools
|
|
|
|
|
import operator
|
|
|
|
|
import math
|
|
|
|
|
import re
|
|
|
|
|
from Render import Article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -59,6 +60,28 @@ class Cache:
|
|
|
|
|
except Error as e:
|
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
|
|
def markStreamAsRead(self, streamId):
|
|
|
|
|
cur = self.conn.cursor()
|
|
|
|
|
if re.search("^feed/[0-9]+", streamId):
|
|
|
|
|
table = "feeds"
|
|
|
|
|
else:
|
|
|
|
|
table = "categories"
|
|
|
|
|
cur.execute("""select timestamp from """ + table + """ where id = ?""", (streamId,))
|
|
|
|
|
ts = cur.fetchone()[0]
|
|
|
|
|
if self.api.markStreamAsRead(streamId, ts):
|
|
|
|
|
if table == "feeds":
|
|
|
|
|
cur.execute("""select unread_count from feeds where id = ?""", (streamId,))
|
|
|
|
|
uc = int(cur.fetchone()[0])
|
|
|
|
|
cur.execute("""update feeds set unread_count = 0 where id = ?""", (streamId,))
|
|
|
|
|
cur.execute("""update categories set unread_count = unread_count - :uc
|
|
|
|
|
where id in (select category_id from feeds where id = :sID)""", {"uc": uc, "sID": streamId})
|
|
|
|
|
cur.execute("""update articles set is_read = 1 where origin = ?""", (streamId,))
|
|
|
|
|
else:
|
|
|
|
|
cur.execute("""update categories set unread_count = 0 where id = ?""", (streamId,))
|
|
|
|
|
cur.execute("""update feeds set unread_count = 0 where id in (select id from feeds where category_id = ?)""", (streamId,))
|
|
|
|
|
cur.execute("""update articles set is_read = 1 where category_id = ?""", (streamId,))
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
|
|
|
|
|
def getArticle(self, id):
|
|
|
|
|
cur = self.conn.cursor()
|
|
|
|
|
cur.execute("""select title,content,url from articles where id = ?""", (id,))
|
|
|
|
|
@ -114,12 +137,17 @@ class Cache:
|
|
|
|
|
return cur.fetchall()
|
|
|
|
|
|
|
|
|
|
def refresh(self):
|
|
|
|
|
timestamps = {}
|
|
|
|
|
cur = self.conn.cursor()
|
|
|
|
|
cur.execute("""select id, timestamp from categories""")
|
|
|
|
|
for row in cur.fetchall():
|
|
|
|
|
timestamps[row[0]] = row[1]
|
|
|
|
|
|
|
|
|
|
self.api.refresh()
|
|
|
|
|
for item in self.api.unreadCounts.keys():
|
|
|
|
|
if item[0:13] != "user/-/label/":
|
|
|
|
|
continue
|
|
|
|
|
data = self.api.unreadCounts[item]
|
|
|
|
|
cur = self.conn.cursor()
|
|
|
|
|
cur.execute("""insert into categories(id,name,unread_count,timestamp,date) values(:id,:name,:count,:ts,:d)
|
|
|
|
|
on conflict(id) do update set unread_count = :count, timestamp = :ts, date = :d;
|
|
|
|
|
""",
|
|
|
|
|
@ -133,15 +161,15 @@ class Cache:
|
|
|
|
|
{"id": item["id"], "name": item["title"], "count": data[0], "ts": data[1], "d": data[2],
|
|
|
|
|
"c_id": item["categories"][0]["id"]})
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
cur.execute("""select c.id, c.name, c.unread_count, c.timestamp,
|
|
|
|
|
cur.execute("""select c.id, c.name, c.unread_count,
|
|
|
|
|
(select count(*) from articles a where a.category_id = c.id) as articles_num from categories c""")
|
|
|
|
|
for row in cur.fetchall():
|
|
|
|
|
yield "Fetching category " + row[1]
|
|
|
|
|
articles = self.api.articlesFromCategory(
|
|
|
|
|
row[0],
|
|
|
|
|
count=str(row[2]),
|
|
|
|
|
timestamp=str(math.floor(row[3] / 1000000)),
|
|
|
|
|
number=row[4])
|
|
|
|
|
timestamp=str(math.floor(timestamps[row[0]] / 1000000)),
|
|
|
|
|
number=row[3])
|
|
|
|
|
for article in articles:
|
|
|
|
|
articleObj = Article(article)
|
|
|
|
|
cur.execute("""insert into articles(id,title,timestamp,date,content,url,is_read,origin,category_id)
|
|
|
|
|
|