Skip to content

Instantly share code, notes, and snippets.

@pmclanahan
Created November 14, 2012 00:46
Show Gist options
  • Save pmclanahan/4069449 to your computer and use it in GitHub Desktop.
Save pmclanahan/4069449 to your computer and use it in GitHub Desktop.
ZNC Notification via Twitter
#!/bin/bash
znc_twitter_notify.py $@
#!/usr/bin/env python
# -*- coding: utf8 -*-
import logging
import re
import subprocess
import sys
DEBUG = False
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
LOG_FILE = "/var/log/znc_cmdnotify.log"
LOG_LEVEL = logging.DEBUG if DEBUG else logging.INFO
logging.basicConfig(level=LOG_LEVEL, format=LOG_FORMAT, filename=LOG_FILE)
def send_msg(msg):
# send using twidge
logging.info("message: %s", msg)
subprocess.call(['twidge', 'dmsend', 'pmclanahan', msg], shell=False)
def main():
msg = ""
for word in sys.argv[1:]:
logging.debug("word: %s", word)
if (len(msg) + len(word)) < 138:
msg += (" " if msg else "") + word
else:
send_msg(msg + "…")
msg = word
send_msg(msg)
if __name__ == "__main__":
logging.debug('argv: %s', sys.argv)
main()
@pmclanahan
Copy link
Author

znc_notify.sh is the one that cmdnotify calls. I thought originally I could call the python directly, but apparently znc_cmdnotify doesn't call the script, it runs it as bash internally. Strange, but this works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment