Example #1
0
from BeautifulSoup import BeautifulSoup
from feedparser import parse
from lib import api


jira_feed_config = api.load_config("./jira.json")
latest = None

def strtodt(string):
    return datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ')

while True:

    feed = parse(jira_feed_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
            api.send_privmsg(jira_feed_config.channel,
                             'JIRA - %s' % re.sub('(\w\w-\d+)',
                                                  '%sbrowse/\\1'%jira_feed_config.jira_url,
                                                  message))

    sleep(jira_feed_config.poll_rate)
Example #2
0
def send_url(chan, msg):
    ret = 'Sending %s to #%s' % (msg, chan)
    api.send_privmsg('#%s' % chan, msg)
    return ret
Example #3
0
def send_json(chan):
    msg = request.json['msg']
    ret = 'Sending %s to #%s' % (msg, chan)
    api.send_privmsg('#%s' % chan, msg)
    return ret
Example #4
0
def send_json():
    msg = request.json['chan']
    msg = request.json['msg']
    ret = 'Sending %s to #%s' % (msg, chan)
    api.send_privmsg('#%s' % chan, msg)
    return ret
Example #5
0
def send_url(chan, msg):
    ret = 'Sending %s to #%s' % (msg, chan)
    api.send_privmsg('#%s' % chan, msg)
    return ret
Example #6
0
import random
import json
from lib import api


api.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():
    index = random.randint(0, len(quote_list) - 1)
    quote = quote_list[index].strip()
    return quote


sub = api.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'):
                api.send_privmsg(message['data']['channel'], get_quote())
        elif message['type'] == 'directed_privmsg':
            if message['data']['message'] == 'twsrs':
                api.send_privmsg(message['data']['channel'], get_quote())