|
|
|
@ -3,6 +3,7 @@ from sqlite3 import Error
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import functools
|
|
|
|
import functools
|
|
|
|
import operator
|
|
|
|
import operator
|
|
|
|
|
|
|
|
import math
|
|
|
|
from Render import Article
|
|
|
|
from Render import Article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -71,12 +72,12 @@ class Cache:
|
|
|
|
|
|
|
|
|
|
|
|
def getArticlesFromFeed(self, feed_id):
|
|
|
|
def getArticlesFromFeed(self, feed_id):
|
|
|
|
cur = self.conn.cursor()
|
|
|
|
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()
|
|
|
|
return cur.fetchall()
|
|
|
|
|
|
|
|
|
|
|
|
def getArticlesFromCategory(self, category_id):
|
|
|
|
def getArticlesFromCategory(self, category_id):
|
|
|
|
cur = self.conn.cursor()
|
|
|
|
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()
|
|
|
|
return cur.fetchall()
|
|
|
|
|
|
|
|
|
|
|
|
def getCategories(self):
|
|
|
|
def getCategories(self):
|
|
|
|
@ -109,10 +110,15 @@ class Cache:
|
|
|
|
{"id": item["id"], "name": item["title"], "count": data[0], "ts": data[1], "d": data[2],
|
|
|
|
{"id": item["id"], "name": item["title"], "count": data[0], "ts": data[1], "d": data[2],
|
|
|
|
"c_id": item["categories"][0]["id"]})
|
|
|
|
"c_id": item["categories"][0]["id"]})
|
|
|
|
self.conn.commit()
|
|
|
|
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():
|
|
|
|
for row in cur.fetchall():
|
|
|
|
yield "Fetching category " + row[1]
|
|
|
|
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:
|
|
|
|
for article in articles:
|
|
|
|
articleObj = Article(article)
|
|
|
|
articleObj = Article(article)
|
|
|
|
cur.execute("""insert into articles(id,title,timestamp,date,content,url,is_read,origin,category_id)
|
|
|
|
cur.execute("""insert into articles(id,title,timestamp,date,content,url,is_read,origin,category_id)
|
|
|
|
|