- Implement creating categories and feeds tables.

- Implement filling categories and feeds tables with data.
sqlite
VikingKong 3 years ago
parent 53c4958ff3
commit 1c6182251e

@ -7,9 +7,11 @@ class Fetcher:
self.URL = URL self.URL = URL
self.token = token self.token = token
self.headers = {"Authorization": "GoogleLogin auth="+token} self.headers = {"Authorization": "GoogleLogin auth="+token}
self.articles = {}
def refresh(self):
self.getUnreadCounts() self.getUnreadCounts()
self.getSubscriptions() self.getSubscriptions()
self.articles = {}
def getUnreadCounts(self): def getUnreadCounts(self):
response = httpx.get(self.URL+"/reader/api/0/unread-count?output=json", headers=self.headers) response = httpx.get(self.URL+"/reader/api/0/unread-count?output=json", headers=self.headers)

@ -6,6 +6,7 @@ import subprocess
import os import os
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from API import Fetcher from API import Fetcher
from DB import DB
from Render import Article from Render import Article
import Utils import Utils
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
@ -281,6 +282,8 @@ class TUI(urwid.Frame):
self.overlay = None self.overlay = None
self.fetcher = Fetcher(URL, token) self.fetcher = Fetcher(URL, token)
self.DB = DB(self.fetcher)
self.DB.refresh()
self.leftPaneItems = {} self.leftPaneItems = {}
self.activePane = False self.activePane = False

55
DB.py

@ -0,0 +1,55 @@
import sqlite3
from sqlite3 import Error
import os
class DB:
def __init__(self, api):
self.conn = None
self.api = api
create_categories = """create table if not exists categories (
id text primary key,
name text not null,
unread_count integer,
timestamp integer,
date text
)
"""
create_feeds = """create table if not exists feeds (
id text primary key,
name text not null,
unread_count integer,
timestamp integer,
date text,
category_id text,
foreign key (category_id) references categories (id)
)
"""
try:
self.conn = sqlite3.connect(os.path.expanduser("~") + '/.config/inomnibus/cache.db')
self.conn.cursor().execute(create_categories)
self.conn.cursor().execute(create_feeds)
except Error as e:
print(e)
def refresh(self):
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;
""",
{"id": item, "name": item[13:], "count": data[0], "ts": data[1], "d": data[2]})
self.conn.commit()
for item in self.api.feeds:
data = self.api.unreadCounts[item["id"]]
cur.execute("""insert into feeds(id,name,unread_count,timestamp,date,category_id) values(:id,:name,:count,:ts,:d,:c_id)
on conflict(id) do update set unread_count = :count, timestamp = :ts, date = :d,category_id = :c_id;
""",
{"id": item["id"], "name": item["title"], "count": data[0], "ts": data[1], "d": data[2],
"c_id": item["categories"][0]["id"]})
self.conn.commit()
Loading…
Cancel
Save