Fix PEP8 compliance in example plugins and rtmbot

This commit is contained in:
Jeff Ammons 2016-04-15 14:03:20 -07:00
parent 6052333c64
commit 25ce082eac
6 changed files with 33 additions and 22 deletions

View file

@ -1,8 +1,9 @@
import time
outputs = []
def canary():
#NOTE: you must add a real channel ID for this to work
# NOTE: you must add a real channel ID for this to work
outputs.append(["D12345678", "bot started: " + str(time.time())])
canary()

View file

@ -2,8 +2,9 @@ import time
crontable = []
outputs = []
crontable.append([5,"say_time"])
crontable.append([5, "say_time"])
def say_time():
#NOTE: you must add a real channel ID for this to work
# NOTE: you must add a real channel ID for this to work
outputs.append(["D12345678", time.time()])

View file

@ -1,8 +1,9 @@
import time
crontable = []
outputs = []
def process_message(data):
if data['channel'].startswith("D"):
outputs.append([data['channel'], "from repeat1 \"{}\" in channel {}".format(data['text'], data['channel']) ])
outputs.append([data['channel'], "from repeat1 \"{}\" in channel {}".format(
data['text'], data['channel'])]
)

View file

@ -6,19 +6,21 @@ crontabs = []
tasks = {}
FILE="plugins/todo.data"
FILE = "plugins/todo.data"
if os.path.isfile(FILE):
tasks = pickle.load(open(FILE, 'rb'))
def process_message(data):
global tasks
channel = data["channel"]
text = data["text"]
#only accept tasks on DM channels
# only accept tasks on DM channels
if channel.startswith("D"):
if channel not in tasks.keys():
tasks[channel] = []
#do command stuff
# do command stuff
if text.startswith("todo"):
tasks[channel].append(text[5:])
outputs.append([channel, "added"])
@ -36,4 +38,4 @@ def process_message(data):
tasks[channel].pop(num)
if text == "show":
print tasks
pickle.dump(tasks, open(FILE,"wb"))
pickle.dump(tasks, open(FILE, "wb"))

View file

@ -1,18 +1,17 @@
#!/usr/bin/env python
import sys
sys.dont_write_bytecode = True
import glob
import yaml
import os
import time
import logging
from argparse import ArgumentParser
from slackclient import SlackClient
sys.dont_write_bytecode = True
def dbg(debug_string):
if debug:
@ -66,14 +65,14 @@ class RtmBot(object):
if limiter:
time.sleep(.1)
limiter = False
message = output[1].encode('ascii','ignore')
message = output[1].encode('ascii', 'ignore')
channel.send_message("{}".format(message))
limiter = True # TODO: check goal: no sleep for 1st channel, sleep of all after ?
limiter = True
# TODO: check goal: no sleep for 1st channel, sleep of all after ?
# TODO: find out how to safely encode stuff if needed :(
# message = output[1].encode('utf-8','ignore')
channel.send_message(output[1]) # message
def crons(self):
for plugin in self.bot_plugins:
plugin.do_jobs()
@ -82,7 +81,8 @@ class RtmBot(object):
for plugin in glob.glob(directory + '/plugins/*'):
sys.path.insert(0, plugin)
sys.path.insert(0, directory + '/plugins/')
for plugin in glob.glob(directory + '/plugins/*.py') + glob.glob(directory + '/plugins/*/*.py'):
for plugin in glob.glob(directory + '/plugins/*.py') + \
glob.glob(directory + '/plugins/*/*.py'):
logging.info(plugin)
name = plugin.split('/')[-1][:-3]
# try:
@ -90,10 +90,12 @@ class RtmBot(object):
# except:
# print "error loading plugin %s" % name
class Plugin(object):
def __init__(self, name, plugin_config=None):
if plugin_config is None:
plugin_config = {} #TODO: is this necessary?
plugin_config = {} # TODO: is this necessary?
self.name = name
self.jobs = []
self.module = __import__(name)
@ -179,7 +181,11 @@ class UnknownChannel(Exception):
def main_loop():
if "LOGFILE" in config:
logging.basicConfig(filename=config["LOGFILE"], level=logging.INFO, format='%(asctime)s %(message)s')
logging.basicConfig(
filename=config["LOGFILE"],
level=logging.INFO,
format='%(asctime)s %(message)s'
)
logging.info(directory)
try:
bot.start()
@ -215,7 +221,7 @@ if __name__ == "__main__":
files_currently_downloading = []
job_hash = {}
if config.has_key("DAEMON"):
if 'DAEMON' in config:
if config["DAEMON"]:
import daemon

View file

@ -20,4 +20,4 @@ basepython =
[testenv:flake8]
basepython=python
deps=flake8
commands=flake8 {toxinidir}/rtmbot.py {toxinidir}/example-plugins
commands=flake8 {toxinidir}/rtmbot.py {toxinidir}/doc/example-plugins