Implement refreshing the content.

sqlite
VikingKong 3 years ago
parent a43c213115
commit c5a2c45c9a

@ -26,29 +26,10 @@ class Fetcher:
def checkCategory(self, category):
return category in self.articles.keys()
def feedsFromCategory(self, category):
return sorted([item for item in self.feeds if item["categories"][0]["id"] == category and self.unreadCounts[item["id"]][0] != 0],
key=lambda item: self.unreadCounts[item["id"]][2], reverse=True)
def articlesFromCategory(self, category, number):
if category not in self.articles:
response = httpx.get(self.URL+"/reader/api/0/stream/contents?n="+number+"&s="+category, headers=self.headers)
def articlesFromCategory(self, category, count=0, timestamp=0, number=0):
if number == 0:
response = httpx.get(self.URL+"/reader/api/0/stream/contents?n="+count+"&s="+category, headers=self.headers)
else:
response = httpx.get(self.URL+"/reader/api/0/stream/contents?ot="+timestamp+"&s="
+ category, headers=self.headers)
return response.json()["items"]
# self.articles[category] = response.json()["items"]
async def articlesFromCategoryAsync(self, category, number):
if category not in self.articles:
response = await httpx.AsyncClient().get(self.URL+"/reader/api/0/stream/contents?n="+number +
"&s="+category, headers=self.headers)
self.articles[category] = response.json()["items"]
def articlesFromFeed(self, feed, category):
try:
return [article for article in self.articles[category] if article["origin"]["streamId"] == feed]
except BaseException:
return None
def fetch(self):
for category in self.categories:
yield "Fetching category " + category["name"]
self.articlesFromCategory(category["id"], str(self.unreadCounts[category["id"]][0]))

@ -3,6 +3,7 @@ from sqlite3 import Error
import os
import functools
import operator
import math
from Render import Article
@ -71,12 +72,12 @@ class Cache:
def getArticlesFromFeed(self, feed_id):
cur = self.conn.cursor()
cur.execute("""select * from articles where origin = ?""", (feed_id,))
cur.execute("""select * from articles where origin = ? order by timestamp desc""", (feed_id,))
return cur.fetchall()
def getArticlesFromCategory(self, category_id):
cur = self.conn.cursor()
cur.execute("""select * from articles where category_id = ?""", (category_id,))
cur.execute("""select * from articles where category_id = ? order by timestamp desc""", (category_id,))
return cur.fetchall()
def getCategories(self):
@ -109,10 +110,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 id, name, unread_count from categories""")
cur.execute("""select c.id, c.name, c.unread_count, c.timestamp,
(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], str(row[2]))
articles = self.api.articlesFromCategory(
row[0],
count=str(row[2]),
timestamp=str(math.floor(row[3] / 1000000)),
number=row[4])
for article in articles:
articleObj = Article(article)
cur.execute("""insert into articles(id,title,timestamp,date,content,url,is_read,origin,category_id)

Loading…
Cancel
Save