Created
May 3, 2023 00:12
-
-
Save IonianIronist/bbce13d36da8ae5ca083048bc7d40b4b to your computer and use it in GitHub Desktop.
anynews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
import sqlite3 | |
import subprocess | |
from urllib.parse import urlparse | |
def get_netloc(url): | |
return urlparse(url).netloc | |
cmd = ["newsboat", "-x", "reload"] | |
subprocess.run(cmd) | |
dbpath = 'PATH_TO_cache.db' | |
conn = sqlite3.connect(dbpath) | |
cur = conn.cursor() | |
qry = """ | |
SELECT | |
STRFTIME('%d/%m %H:%M', DATE(pubDate, 'unixepoch')), | |
feedurl, | |
title, | |
url | |
FROM | |
rss_item | |
WHERE | |
unread=1 | |
ORDER BY pubDate DESC | |
LIMIT 1 | |
""" | |
res = cur.execute(qry) | |
newest_article = res.fetchone() | |
qry = """ | |
SELECT | |
count(*) | |
FROM | |
rss_item | |
WHERE | |
unread=1 | |
""" | |
res = cur.execute(qry) | |
unread_count = res.fetchone()[0] | |
msg = f"Found {unread_count} unread articles.\n\nThe most recent one:\n\n{newest_article[0]}\nTitle: {newest_article[2]}\n\nNewspaper: {get_netloc(newest_article[1])}\n\n{newest_article[3]}" | |
print(msg) | |
prompt = "Open newsboat to read the news? (y/n)\n" | |
response = input(prompt) | |
if response == 'y': | |
subprocess.run('newsboat') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment