@@ -0,0 +1,2612 @@
+#!/usr/bin/env python%0A%22%22%22%0A%0ASlackbot for ELOG%0A%0A%22%22%22%0Aimport os%0A%0Aimport pyinotify%0A%0Afrom pyslack import SlackClient%0A%0A%0Awm = pyinotify.WatchManager()%0Amask = pyinotify.IN_CLOSE_WRITE%0A%0AURL = 'http://elog.whatever.com'%0ALOGBOOK_PATH = '/usr/local/elog/logbooks'%0ABOTNAME = 'ELOG'%0ADESTINATIONS = %7B%0A    'Operations IT': '@tgal',%0A    'Operations FR': '@tgal',%0A    'Qualification': '@tgal',%0A    'DOM Integration': '@tgal',%0A    'DU Integration': '@tgal',%0A    'DAQ Readout': '@tgal',%0A    'Electronics': '@tgal',%0A    'Analysis': '@tgal',%0A    'Computing and Software': '@tgal',%0A    %7D%0A%0Aslack = SlackClient('YOUR-SLACK-API-TOKEN')%0A%0A%0Aclass EventHandler(pyinotify.ProcessEvent):%0A    def process_IN_CLOSE_WRITE(self, event):%0A        if not self._is_valid_filetype(event.pathname):%0A            return%0A%0A        try:%0A            elog_entry = ElogEntry(event.pathname)%0A        except ValueError:%0A            print(%22Could not parse '%7B0%7D'. Ignoring...%22.format(event.pathname))%0A            return%0A%0A        try:%0A            destination = DESTINATIONS%5Belog_entry.logbook%5D%0A        except KeyError:%0A            print(%22No destination for logbook '%7B0%7D'. Ignoring...%22.format(elog_entry.logbook))%0A        else:%0A            slack.chat_post_message(destination, elog_entry, username=BOTNAME)%0A%0A    def _is_valid_filetype(self, path):%0A        return path.endswith('.log')%0A%0A%0Aclass ElogEntry(object):%0A    def __init__(self, pathname):%0A        self.logbook = dirname(pathname)%0A        self.author = None%0A        self.subject = None%0A        self.type = None%0A        self.id = None%0A        with open(pathname, 'r') as input_file:%0A            for line in input_file:%0A                if line.startswith('Author:'):%0A                    self.author = line.split(':')%5B1%5D.strip()%0A                if line.startswith('Subject:'):%0A                    self.subject = line.split(':')%5B1%5D.strip()%0A                if line.startswith('Type:'):%0A                    self.type = line.split(':')%5B1%5D.strip()%0A                if line.startswith('$@MID@$:'):%0A                    self.id = line.split(':')%5B1%5D.strip()%0A        if not all((self.author, self.subject, self.type, self.id)):%0A            raise ValueError%0A        self.url = URL + '/' + self.logbook.replace(' ', '+') + '/' + self.id%0A%0A    def __repr__(self):%0A        return (%22ElogEntry from *%7B0.author%7D* in *%7B0.logbook%7D* (_%7B0.type%7D_):%5Cn%22%0A                %22*%7B0.subject%7D*%5Cn%7B0.url%7D%22%0A                .format(self))%0A%0A%0Adef dirname(filepath):%0A    return os.path.basename(os.path.dirname(filepath))%0A%0A%0Ahandler = EventHandler()%0Anotifier = pyinotify.Notifier(wm, handler)%0Awdd = wm.add_watch(LOGBOOK_PATH, mask, rec=True)%0A%0Anotifier.loop()%0A

Create elog-slack.py