Created
November 14, 2012 00:46
-
-
Save pmclanahan/4069449 to your computer and use it in GitHub Desktop.
ZNC Notification via Twitter
This file contains hidden or 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/bash | |
znc_twitter_notify.py $@ |
This file contains hidden or 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
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 asbash
internally. Strange, but this works.