コード例 #1
0
ファイル: lexicon.py プロジェクト: saarioka/raspberry-slack
import logging
import sys
import re
import time
import random
import utils

logger = utils.loggerMaster('slack.lexicon')


def response(type):

    phrases = {
        'greetings': [
            ", welcome back", "Hi there", "Good to see you again",
            "Hello again", "hi"
        ],
        'farewells': ['bye']
    }

    try:
        length = len(phrases[type])
        return phrases[type][(random.randint(0, length - 1))]
    except KeyError:
        logger.error('lexicon read error')
        return ('There is an error in the lexicon file you idiot')


def main():
    print "This is a module designed to be used with RaspiSlack"
コード例 #2
0
#date last modified: 17/5/2017

import time
import sys

from slackclient import SlackClient
import psutil

import config
import utils
import lexicon as lx
import SlackBot

# logging module

logger = utils.loggerMaster('slack', logLevel="DEBUG")

from utils import get_temp as temp

#add directory for author testing

sys.path.append('./testing/')

# get authentication details from config file

if len(sys.argv) > 1:

    if sys.argv[1] == 'dev':
        logger.info('dev mode')
        location = './testing/dev_config.conf'
    else:
コード例 #3
0
"""Config parser to handle slack config files"""

import ConfigParser
import logging
import utils
import sys, os

logger = utils.loggerMaster('slack.config')


def read_config(file):

    logger.info("Reading config file...")
    config = ConfigParser.SafeConfigParser()
    if not os.path.isfile(file):
        logger.error("config file not found")
        sys.exit("config file not found")
    config.read(file)

    dictionary = {}

    for section in config.sections():
        dictionary.update(dict(config.items(section)))

    logger.info("testing module logging")

    return dictionary


if __name__ == ("__main__"):
コード例 #4
0
import re

import utils, config, subprocess

logger=utils.loggerMaster("slack.plugin_motion")

def plugin_main(message, host):

    logger.debug("testing plugin")
    
    if re.match(r'.*(snapshot).*', message, re.IGNORECASE):

        configs=host.config
        WEBCAM_IP=configs['webcam_ip']
        MOTION_FOLDER=configs['motion_folder']

        subprocess.call(
                            'curl -s -o /dev/null http://' +
                            WEBCAM_IP +
                            ':8080/0/action/snapshot',
                            shell=True)

        subprocess.call(
                            "curl -F file=@" +
                            MOTION_FOLDER +
                            "lastsnap.jpg -F channels=#" +
                            host.channel_name +
                            " -F token=" +
                            host.token +
                            " https://slack.com/api/files.upload",
                            shell=True)
コード例 #5
0
import re
import sys
import utils

logger=utils.loggerMaster("slack.plugin_test")

def plugin_main(message, host):

    logger.debug("testing plugin")
    if re.match(r'.*(shut).*', message, re.IGNORECASE):

        host.say("Shutting down")
        sys.exit("shutting down")
        pass
コード例 #6
0
ファイル: SlackBot.py プロジェクト: saarioka/raspberry-slack
import sys
import logging
import socket
import signal

from slackclient import SlackClient
import psutil

import utils
import lexicon as lex

sys.path.append('./plugins/')

# logging module

logger = utils.loggerMaster('slack.bot')


class SlackBot():
    """master slack client that remains alive for the duration of the script.  subsidiary connections to SlackClient are made on each connection drop or error"""
    def __init__(self, config):

        self.config = config
        self.token = self.config['api_key']
        self.slack_client = None
        self.name = self.config['bot_name']
        self.slack_user_id = None
        self.direct_message_channels = None
        self.channel_id = None
        self.channel_name = None
        self.master = self.config['master']
コード例 #7
0
import re

import utils, psutil
import subprocess
import router
import json

logger = utils.loggerMaster("slack.plugin_status")


def plugin_main(message, host):

    logger.debug("testing plugin")

    if re.match(r'.*(status).*', message, re.IGNORECASE):

        cpu_pct = psutil.cpu_percent(interval=1, percpu=False)
        temp = utils.get_temp()
        host.say(
            "Hi, my CPU is at %s%%.  My temperature is %s.  I've been running Slack for %d seconds since last interrupt.  Total run time %d seconds"
            % (cpu_pct, temp, host.run_time, host.run_time_total))
        uptime = subprocess.check_output('uptime', shell=True)
        uptime = uptime.split('1 user')
        host.say("Uptime:  " + str(uptime[0]))

    elif re.match(r'.*(router).*', message, re.IGNORECASE):

        devices = host.config['known_devices']
        devices = devices.replace("'", "\"")
        known_devices = json.loads(devices)
        ip = psutil.net_if_addrs()['wlan0'][0][1]