Skip to content

Instantly share code, notes, and snippets.

@Lucas-C
Last active September 19, 2019 21:56
Show Gist options
  • Save Lucas-C/42373e6451a28e4c59026c129c1abb73 to your computer and use it in GitHub Desktop.
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: https://posativ.org/isso - 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 comments.id, text, author, uri FROM comments INNER JOIN threads on comments.tid = threads.id'
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(f.read())
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 c.id > 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, comment.author, uri))
with open(last_comment_id_filepath, 'w') as f:
f.write('{}'.format(new_comments[-1].id))
#!/bin/bash
set -o pipefail -o errexit -o nounset
date
cd $(dirname "${BASH_SOURCE[0]}")
./isso_watcher.py isso_watcher.last_comment_id \
$ISSO_HOME/isso.db \
$SITE_BASE_URL \
> new_comments
if [ -s new_comments ]; then
echo "New comments created, sending notification"
mail -s '[isso_watcher] New comments posted' $EMAIL < new_comments
fi
rm new_comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment