def test_slack_call(self, mock_call): gendo = Gendo(TEST_TOKEN) gendo.speak(TEST_TEXT, TEST_CHANNEL) mock_call.assert_called_with('chat.postMessage', as_user='******', channel='tests', text=TEST_TEXT)
def test_slack_call(self, mock_call): gendo = Gendo(TEST_TOKEN) gendo.speak(TEST_TEXT, TEST_CHANNEL) mock_call.assert_called_with( 'chat.postMessage', as_user='******', channel='tests', text=TEST_TEXT )
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import requests from gendo import Gendo path = os.path.dirname(os.path.abspath(__file__)) path_to_yaml = os.path.join(path, 'config.yaml') gendo = Gendo.config_from_yaml(path_to_yaml) @gendo.listen_for('cookies') def cookies(user, message): return "I *LOVE* COOOOOOOOKIES!!!!" @gendo.listen_for('morning') def morning(user, message): # make sure message is "morning" and doesn't just contain it. if message.strip() == "morning": return "mornin' @{user.username}" @gendo.cron('0 15 * * *') def quote_of_the_day(): """Quote of the day""" url = 'http://api.theysaidso.com/qod.json' resp = requests.get(url) if not resp.ok: return quote = resp.json().get('contents', {}).get('quotes', [])[0]
#!/usr/bin/env python # -*- coding: utf-8 -*- import os from gendo import Gendo import requests import re gendo = Gendo("xoxb-243402108406-A76uco7GUr1alochyQxGzKvQ") path = os.path.dirname(os.path.abspath(__file__)) path_to_yaml = os.path.join(path, 'config.yaml') gendo1 = Gendo.config_from_yaml(path_to_yaml) keywords = [ u'ăn trưa', 'an trua', 'tra sua', u'trà sữa', u'cơm trưa', 'com trua', u'cơm', 'com', u'gà', 'ga' ] req = requests.get( 'https://www.deliverynow.vn/Offer/LoadMore?pageIndex=0&provinceId=217') coupon_info = req.json() @gendo.listen_for('cookies') def cookies(user, message): return 'I *LOVE* COOOOOOOOKIES!!!!' @gendo.cron('0 9 * * *') def cookies(user, message): return 'morning everyonee'
def test_speak(self, mock_speak): gendo = Gendo(TEST_TOKEN) gendo.speak(TEST_TEXT, TEST_CHANNEL) mock_speak.assert_called_with(TEST_TEXT, TEST_CHANNEL)
# 3rd party library from gendo import Gendo from sqlalchemy.orm import sessionmaker # Local library from parktain.models import Base, Channel, engine, Message, User Session = sessionmaker(bind=engine) session = Session() HERE = dirname(abspath(__file__)) URL_RE = re.compile('<(https{0,1}://.*?)>') config_path = join(HERE, 'config.yaml') bot = Gendo.config_from_yaml(config_path) if exists(config_path) else Gendo() #### Helper functions ######################################################### def all_messages(user, channel, message): return True def is_mention(f): """Decorator to check if bot is mentioned.""" def wrapped(user, channel, message): BOT_ID_RE = re.compile('<@{}>'.format(bot.id)) mention = BOT_ID_RE.search(message) is not None if mention: return f(user, channel, message)
from email_parser import get_latest_mails_bigger_than from configobj import ConfigObj from config_init import init_config from gendo import Gendo # Your Slack token. Should be in a config file or envvar gendo = Gendo('xoxb-xxxxxxxxx-xxxxxxxxxxxxxxxxxx') # This one should also be there slack_channel = "mails-and-stuff" def get_new_emails(): config = ConfigObj('config.ini') for provider, p in config["Accounts"].items(): mails = get_latest_mails_bigger_than(p["imap_dir"], p["user"], p["pass"], p["latest_id"]) if len(mails) > 0: gendo.speak( "New emails at *{0}* ({1})".format(provider, p["link"]), slack_channel) gendo.speak('\n'.join(mails), slack_channel) init_config() @gendo.listen_for('check mails') def check_mails(user, message): get_new_emails()
import redis import yaml import random import re import requests from gendo import Gendo path = os.path.dirname(os.path.abspath(__file__)) path_to_yaml = os.path.join(path, 'config.yaml') with open(path_to_yaml, 'r') as ymlfile: cfg = yaml.load(ymlfile) channel = cfg.get('gendo', {}).get('channel') token = cfg.get('gendo', {}).get('auth_token') gendo = Gendo(__name__, token, channel) db = None def setup_redis(): global db db = redis.StrictRedis(host='localhost', port=6379, db=0) @gendo.listen_for('cookies') def cookies(user, message): return "I *LOVE* COOOOOOOOKIES!!!!" @gendo.listen_for('morning')