Skip to content

Instantly share code, notes, and snippets.

@IonianIronist
Created May 3, 2023 00:12
Show Gist options
  • Save IonianIronist/bbce13d36da8ae5ca083048bc7d40b4b to your computer and use it in GitHub Desktop.
Save IonianIronist/bbce13d36da8ae5ca083048bc7d40b4b to your computer and use it in GitHub Desktop.
anynews
#!/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