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