Skip to content

Instantly share code, notes, and snippets.

Last active September 19, 2019 21:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Lucas-C/42373e6451a28e4c59026c129c1abb73 to your computer and use it in GitHub Desktop.
A script to cron in order to get notified by email on new isso comments: - The bash script calls the Python one
#!/usr/bin/env python3 import sqlite3, sys
from collections import namedtuple
Comment = namedtuple('_Comment', ('id', 'text', 'author', 'uri'))
QUERY = 'SELECT, text, author, uri FROM comments INNER JOIN threads on comments.tid ='
last_comment_id_filepath = sys.argv[1]
isso_db_filepath = sys.argv[2]
uri_prefix = sys.argv[3] if len(sys.argv) == 4 else ''
with open(last_comment_id_filepath) as f:
last_comment_id = int(
db = sqlite3.connect(isso_db_filepath)
new_comments = [Comment(*result) for result in db.execute(QUERY).fetchall()]
new_comments = [c for c in new_comments if > last_comment_id]
if new_comments:
for comment in new_comments:
uri = uri_prefix + ('/shaarli?' if len(comment.uri) == 6 else '') + comment.uri # yes, this is an ugly non-generic hack :(
print('{} - {} - {}'.format(comment.text,, uri))
with open(last_comment_id_filepath, 'w') as f:
set -o pipefail -o errexit -o nounset
cd $(dirname "${BASH_SOURCE[0]}")
./ isso_watcher.last_comment_id \
$ISSO_HOME/isso.db \
> new_comments
if [ -s new_comments ]; then
echo "New comments created, sending notification"
mail -s '[isso_watcher] New comments posted' $EMAIL < new_comments
rm new_comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment