import re import requests import sys from zenircbot_api import ZenIRCBot, load_config bot_config = load_config('../bot.json') zen = ZenIRCBot(bot_config['redis']['host'], bot_config['redis']['port'], bot_config['redis']['db']) ISSUE = re.compile('^#(\d*)| #(\d*)') URL = 'https://api.github.com/repos/%s/issues/{nb}' % sys.argv[1] sub = zen.get_redis_client().pubsub() sub.subscribe('in') for msg in sub.listen(): if msg['type'] != 'message': continue message = json.loads(msg['data']) if message['version'] == 1: if message['type'] == 'privmsg': text = message['data']['message'] match = ISSUE.search(text) if match: issue_nb = match.groups()[0] or match.groups()[1] resp = requests.get(URL.format(nb=issue_nb)) if resp.status_code == 200: msg = "{title} ({state}) - {html_url}".format(**resp.json) zen.send_privmsg(message['data']['channel'], msg)
} ], ) quote_list = open("twsrs_quotes.txt").readlines() def get_quote(): """get_quote""" index = random.randint(0, len(quote_list) - 1) quote = quote_list[index].strip() return quote sub = zen.get_redis_client().pubsub() sub.subscribe("in") for msg in sub.listen(): message = json.loads(msg["data"]) if message["version"] == 1: if message["type"] == "privmsg": text = message["data"]["message"] # Change to ascii and drop unicode chars. text = text.encode("ascii", "ignore").lower() # Drop other chars that we don't like.' text = text.translate(None, """`~!@#$%^&*()_-+={}[];:'"<>,.?/""") if text.startswith("thats what she said"): zen.send_privmsg(message["data"]["channel"], get_quote()) elif message["type"] == "directed_privmsg": if message["data"]["message"] == "twsrs": zen.send_privmsg(message["data"]["channel"], get_quote())
zen.register_commands('jira_feed.py', []) jira_config = load_config("./jira.json") jira_url = '%sbrowse/\\1' % jira_config['jira_url'] latest = None def strtodt(string): return datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ') while True: feed = parse(jira_config['feed_url']) if latest is None: latest = strtodt(feed['entries'][0].updated) - timedelta(seconds=1) entries = [ entry for entry in feed['entries'] if strtodt(entry.updated) > latest ] for entry in entries: if strtodt(entry.updated) > latest: latest = strtodt(entry.updated) bs = BeautifulSoup(entry.title) message = ''.join(bs.findAll(text=True)) if not ('created' in message or 'resolved' in message or 'reopened' in message): continue zen.send_privmsg( jira_config['channels'], 'JIRA - %s' % re.sub('(?:\s|^)([a-zA-Z][a-zA-Z]-\d+)', jira_url, message)) sleep(jira_config['poll_rate'])
bot_config['redis']['port'], bot_config['redis']['db']) zen.register_commands('twsrs.py', [{'name': 'that\'s what she said', 'description': 'Replies to "That\'s what she said" with quotes from famous women'}]) quote_list = open('twsrs_quotes.txt').readlines() def get_quote(): """get_quote""" index = random.randint(0, len(quote_list) - 1) quote = quote_list[index].strip() return quote sub = zen.get_redis_client().pubsub() sub.subscribe('in') for msg in sub.listen(): message = json.loads(msg['data']) if message['version'] == 1: if message['type'] == 'privmsg': text = message['data']['message'] text = text.encode('ascii', 'ignore').lower().translate(None, """`~!@#$%^&*()_-+={}[];:'"<>,.?/""") if text.startswith('thats what she said'): zen.send_privmsg(message['data']['channel'], get_quote()) elif message['type'] == 'directed_privmsg': if message['data']['message'] == 'twsrs': zen.send_privmsg(message['data']['channel'], get_quote())
'description': ('Replies to "That\'s what she said" with quotes from ' 'famous women') }]) quote_list = open('twsrs_quotes.txt').readlines() def get_quote(): """get_quote""" index = random.randint(0, len(quote_list) - 1) quote = quote_list[index].strip() return quote sub = zen.get_redis_client().pubsub() sub.subscribe('in') for msg in sub.listen(): message = json.loads(msg['data']) if message['version'] == 1: if message['type'] == 'privmsg': text = message['data']['message'] # Change to ascii and drop unicode chars. text = text.encode('ascii', 'ignore').lower() # Drop other chars that we don't like.' text = text.translate(None, """`~!@#$%^&*()_-+={}[];:'"<>,.?/""") if text.startswith('thats what she said'): zen.send_privmsg(message['data']['channel'], get_quote()) elif message['type'] == 'directed_privmsg': if message['data']['message'] == 'twsrs': zen.send_privmsg(message['data']['channel'], get_quote())
jira_config = load_config("./jira.json") jira_url = '%sbrowse/\\1' % jira_config['jira_url'] latest = None def strtodt(string): return datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ') while True: feed = parse(jira_config['feed_url']) if latest is None: latest = strtodt(feed['entries'][0].updated) - timedelta(seconds=1) entries = [entry for entry in feed['entries'] if strtodt(entry.updated) > latest] for entry in entries: if strtodt(entry.updated) > latest: latest = strtodt(entry.updated) bs = BeautifulSoup(entry.title) message = ''.join(bs.findAll(text=True)) if not ('created' in message or 'resolved' in message or 'reopened' in message): continue zen.send_privmsg(jira_config['channels'], 'JIRA - %s' % re.sub('(?:\s|^)([a-zA-Z][a-zA-Z]-\d+)', jira_url, message)) sleep(jira_config['poll_rate'])
] # zen.register_commands(__file__, commands) funday_url = 'http://fundayroulette.com/api/v1/funday/random/?format=json' def debug(data): return zen.send_privmsg('#pdxbots', str(data)) sub = zen.get_redis_client().pubsub() sub.subscribe('in') for msg in sub.listen(): debug(msg) if msg['type'] == 'subscribe': continue message = json.loads(msg['data']) if message['version'] == 1: debug('version==1') if message['type'] == 'directed_privmsg': debug('directed') data = message['data'] if data['message'] == 'funday': debug('funday') res = requests.get(funday_url) funday = json.loads(res.content) zen.send_privmsg(data['channel'], '%s: %s' % (funday['name'], funday['description']))
from zenircbot_api import ZenIRCBot, load_config bot_config = load_config('../bot.json') zen = ZenIRCBot(bot_config['redis']['host'], bot_config['redis']['port'], bot_config['redis']['db']) ISSUE = re.compile('^#(\d*)| #(\d*)') URL = 'https://api.github.com/repos/%s/issues/{nb}' % sys.argv[1] sub = zen.get_redis_client().pubsub() sub.subscribe('in') for msg in sub.listen(): if msg['type'] != 'message': continue message = json.loads(msg['data']) if message['version'] == 1: if message['type'] == 'privmsg': text = message['data']['message'] match = ISSUE.search(text) if match: issue_nb = match.groups()[0] or match.groups()[1] resp = requests.get(URL.format(nb=issue_nb)) if resp.status_code == 200: msg = "{title} ({state}) - {html_url}".format(**resp.json) zen.send_privmsg(message['data']['channel'], msg)
# zen.register_commands(__file__, commands) funday_url = 'http://fundayroulette.com/api/v1/funday/random/?format=json' def debug(data): return zen.send_privmsg('#pdxbots', str(data)) sub = zen.get_redis_client().pubsub() sub.subscribe('in') for msg in sub.listen(): debug(msg) if msg['type'] == 'subscribe': continue message = json.loads(msg['data']) if message['version'] == 1: debug('version==1') if message['type'] == 'directed_privmsg': debug('directed') data = message['data'] if data['message'] == 'funday': debug('funday') res = requests.get(funday_url) funday = json.loads(res.content) zen.send_privmsg( data['channel'], '%s: %s' % (funday['name'], funday['description']))