Update slixfeed.py

This commit is contained in:
Schimon Jehudah 2022-08-17 13:32:25 +00:00
parent 692faed8ee
commit 0c32f95814

View file

@ -397,6 +397,7 @@ def create_table(conn, create_table_sql):
# def setup_info(jid):
# def start_process(jid):
async def download_updates(conn, lock):
async with lock:
print("download_updates(conn, lock)")
with conn:
# cur = conn.cursor()
@ -407,7 +408,6 @@ async def download_updates(conn, lock):
#"".join(url)
source = url[0]
res = await download_feed(conn, source)
await lock.acquire()
cur = conn.cursor()
sql = "UPDATE feeds SET status = :status, scanned = :scanned WHERE address = :url"
cur.execute(sql, {"status": res[1], "scanned": date.today(), "url": source})
@ -429,7 +429,6 @@ async def download_updates(conn, lock):
conn.commit()
except (IncompleteReadError, IncompleteRead, error.URLError) as e:
print(e)
lock.release()
return
# TODO Place these couple of lines back down
# NOTE Need to correct the SQL statement to do so
@ -456,7 +455,6 @@ async def download_updates(conn, lock):
entry = (title, summary, link, source, 0);
await add_entry(conn, entry)
await set_date(conn, source)
lock.release()
#make_message
# message = title + '\n\n' + summary + '\n\nLink: ' + link
# print(message)
@ -485,12 +483,11 @@ async def check_feed(conn, lock, url):
:param url:
:return: row
"""
await lock.acquire()
async with lock:
cur = conn.cursor()
print(time.strftime("%H:%M:%S"), "conn.cursor() from check_feed(conn, url)")
sql = "SELECT id FROM feeds WHERE address = ?"
cur.execute(sql, (url,))
lock.release()
return cur.fetchone()
async def add_feed(conn, lock, url):
@ -500,6 +497,7 @@ async def add_feed(conn, lock, url):
:param feed:
:return: string
"""
async with lock:
print("add_feed(conn, lock, url)")
#TODO consider async with lock
#conn = create_connection(db_file)
@ -510,14 +508,12 @@ async def add_feed(conn, lock, url):
res = await download_feed(conn, url)
if res[0]:
feed = feedparser.parse(res[0])
await lock.acquire()
if feed.bozo:
feed = (url, 1, res[1], 0)
sql = """INSERT INTO feeds(address,enabled,status,valid)
VALUES(?,?,?,?) """
cur.execute(sql, feed)
conn.commit()
lock.release()
bozo = ("WARNING: Bozo detected. Failed to load URL.")
print(bozo)
return "Failed to parse URL as feed"
@ -528,14 +524,12 @@ async def add_feed(conn, lock, url):
VALUES(?,?,?,?,?) """
cur.execute(sql, feed)
conn.commit()
lock.release()
else:
feed = (url, 1, res[1], 0)
sql = """INSERT INTO feeds(address,enabled,status,valid)
VALUES(?,?,?,?) """
cur.execute(sql, feed)
conn.commit()
lock.release()
return "Failed to get URL. HTTP Error {}".format(res[1])
print(time.strftime("%H:%M:%S"), "conn.commit() from add_feed(conn, url)")
# source = title if not '' else url
@ -553,10 +547,10 @@ async def remove_feed(conn, lock, id):
:param id: id of the feed
:return: string
"""
async with lock:
print("remove_feed(conn, lock, id)")
# You have chose to remove feed (title, url) from your feed list.
# Enter "delete" to confirm removal.
await lock.acquire()
#conn = create_connection(db_file)
cur = conn.cursor()
print(time.strftime("%H:%M:%S"), "conn.cursor() from remove_feed(conn, id)")
@ -570,7 +564,6 @@ async def remove_feed(conn, lock, id):
sql = "DELETE FROM feeds WHERE id = ?"
cur.execute(sql, (id,))
conn.commit()
lock.release()
print(time.strftime("%H:%M:%S"), "conn.commit() from remove_feed(conn, id)")
return """News source <{}> has been removed from subscriptions list
""".format(url)
@ -620,17 +613,17 @@ async def mark_as_read(conn, lock, id):
:param conn:
:param id: id of the entry
"""
async with lock:
cur = conn.cursor()
print(time.strftime("%H:%M:%S"), "conn.cursor() from mark_as_read(conn, id)")
sql = "UPDATE entries SET summary = '', read = 1 WHERE id = ?"
await lock.acquire()
cur.execute(sql, (id,))
conn.commit()
lock.release()
print(time.strftime("%H:%M:%S"), "conn.commit() from mark_as_read(conn, id)")
#conn.close()
async def feed_refresh(conn, lock, id):
async with lock:
cur = conn.cursor()
sql = "SELECT address FROM feeds WHERE id = :id"
cur.execute(sql, (id,))
@ -639,10 +632,8 @@ async def feed_refresh(conn, lock, id):
feed = feedparser.parse(res[0])
title = feed["feed"]["title"]
sql = "UPDATE feeds SET name = :name WHERE address = :url"
await lock.acquire()
cur.execute(sql, {"name": title, "url": url})
conn.commit()
lock.release()
# TODO mark_all_read for entries of feed
async def toggle_status(conn, lock, id):
@ -653,7 +644,7 @@ async def toggle_status(conn, lock, id):
:return: string
"""
print("toggle_status(conn, lock, id)")
await lock.acquire()
async with lock:
#conn = create_connection(db_file)
cur = conn.cursor()
print(time.strftime("%H:%M:%S"), "conn.cursor() from toggle_status(conn, id)")
@ -676,7 +667,6 @@ async def toggle_status(conn, lock, id):
sql = "UPDATE feeds SET enabled = :status WHERE id = :id"
cur.execute(sql, {"status": status, "id": id})
conn.commit()
lock.release()
print(time.strftime("%H:%M:%S"), "conn.commit() from toggle_status(conn, id)")
return notice