예제 #1
0
def verify_channel(channel):
    channels = util.irc_channels(current_app.config['IRC_CHANNELS'])
    if channel is None:
        return channels[0]['name']
    channel = u'#' + channel
    channel_names = (i['name'] for i in channels)
    if channel not in channel_names:
        flask.abort(404)
    return channel
예제 #2
0
def verify_channel(channel):
    channels = util.irc_channels(current_app.config['IRC_CHANNELS'])
    if channel is None:
        return channels[0]['name']
    channel = u'#' + channel
    channel_names = (i['name'] for i in channels)
    if channel not in channel_names:
        flask.abort(404)
    return channel
예제 #3
0
def index():
    channels = util.irc_channels(current_app.config['IRC_CHANNELS'])
    logs = []
    for i in channels:
        log = Log.today(i['name'])
        message = list(log.get_messages())[-5:]
        logs.append(dict(
            log=log,
            message=message,
        ))
    return render_template('index.html', logs=logs)
예제 #4
0
def index():
    channels = util.irc_channels(current_app.config['IRC_CHANNELS'])
    logs = []
    for i in channels:
        log = Log.today(i['name'])
        message = list(log.get_messages())[-5:]
        logs.append(dict(
            log=log,
            message=message,
        ))
    return render_template('index.html',
                           logs=logs)
예제 #5
0
def index():
    channels = util.irc_channels(current_app.config['IRC_CHANNELS'])
    if len(channels) == 1:
        return redirect(url_for('channel', channel=channels[0]['name'][1:]))
    logs = []
    for i in channels:
        log = Log.today(i['name'])
        message = list(log.get_messages())[-5:]
        logs.append(dict(
            log=log,
            message=message,
        ))
    return render_template('index.html',
                           logs=logs)
예제 #6
0
def random_(channel):
    if channel is None:
        channels = util.irc_channels(current_app.config['IRC_CHANNELS'])
        channel_names = [i['name'] for i in channels]
    else:
        channel = verify_channel(channel)
    for _ in range(10):
        chan = channel or random.choice(channel_names)
        ago = random.randrange(30, 600)
        rand = datetime.date.today() - datetime.timedelta(days=ago)
        log = Log(chan, rand)
        if log.exists:
            break
    else:
        return redirect(url_for('index'))
    return redirect(log.url())
예제 #7
0
def random_(channel):
    if channel is None:
        channels = util.irc_channels(current_app.config['IRC_CHANNELS'])
        channel_names = [i['name'] for i in channels]
    else:
        channel = verify_channel(channel)
    for _ in range(10):
        chan = channel or random.choice(channel_names)
        ago = random.randrange(30, 600)
        rand = datetime.date.today() - datetime.timedelta(days=ago)
        log = Log(chan, rand)
        if log.exists:
            break
    else:
        return redirect(url_for('index'))
    return redirect(log.url())
예제 #8
0
def log(channel, date):
    if channel is None:
        channel = get_default_channel()['name'][1:]
        return redirect(url_for('log', channel=channel, date=date))
    channel = verify_channel(channel)
    channels = util.irc_channels(current_app.config['IRC_CHANNELS'])
    channel_names = [i['name'][1:] for i in channels
                                   if i['name'].startswith('#')]
    log = Log(channel, date)
    if not log.exists and not log.is_today:
        flask.abort(404)
    if 'from' in request.args:
        start = int(request.args['from'])
    else:
        start = None
    messages = list(log.get_messages(start=start))
    if messages:
        last_no = max(msg['no'] for msg in messages)
    else:
        last_no = 0
    if request.is_xhr:
    	if messages:
            html = render_template('_messages.html',
                                   log=log, messages=messages, last_no=last_no)
            return jsonify(html=html, last_no=last_no)
        else:
        	return jsonify(html=None)
    options = {}
    if log.is_today and 'recent' in request.args:
        recent = int(request.args['recent'])
        messages, truncated = filter_recent(messages, recent)
        if truncated:
            options['recent'] = recent
    messages = group_messages(messages, app.config['GROUP_THRES'])
    return render_template('log.html',
                           today=Log.today(channel),
                           log=log,
                           messages=messages,
                           options=options,
                           last_no=last_no,
                           username=session['username'],
                           channel=channel,
                           channels=channel_names)
예제 #9
0
def log(channel, date):
    if channel is None:
        channel = get_default_channel()['name'][1:]
        return redirect(url_for('log', channel=channel, date=date))
    channel = verify_channel(channel)
    channels = util.irc_channels(current_app.config['IRC_CHANNELS'])
    channel_names = [
        i['name'][1:] for i in channels if i['name'].startswith('#')
    ]
    log = Log(channel, date)
    if not log.exists and not log.is_today:
        flask.abort(404)
    if 'from' in request.args:
        start = int(request.args['from'])
    else:
        start = None
    messages = list(log.get_messages(start=start))
    if messages:
        last_no = max(msg['no'] for msg in messages)
    else:
        last_no = 0
    if request.is_xhr:
        return render_template('_messages.html',
                               log=log,
                               messages=messages,
                               last_no=last_no)
    options = {}
    if log.is_today and 'recent' in request.args:
        recent = int(request.args['recent'])
        messages, truncated = filter_recent(messages, recent)
        if truncated:
            options['recent'] = recent
    messages = group_messages(messages, app.config['GROUP_THRES'])
    return render_template('log.html',
                           today=Log.today(channel),
                           log=log,
                           messages=messages,
                           options=options,
                           last_no=last_no,
                           username=session['username'],
                           channel=channel,
                           channels=channel_names)
예제 #10
0
def main():
    print '''<?xml version="1.0" encoding="utf-8"?>
<sphinx:docset>
<sphinx:schema>
    <sphinx:field name="content" attr="string"/>
    <sphinx:attr name="channel" type="string"/>
    <sphinx:attr name="no" type="int" bits="32"/>
    <sphinx:attr name="nick" type="string"/>
    <sphinx:attr name="date" type="int" bits="32"/>
    <sphinx:attr name="time" type="timestamp"/>
    <sphinx:attr name="bot" type="bool"/>
</sphinx:schema>'''
    log_dir = current_app.config['LOG_DIR']
    channels = util.irc_channels(current_app.config['IRC_CHANNELS'])
    channel_names = [i['name'] for i in channels]
    for i, channel in enumerate(channel_names):
        if not channel.startswith('#'):
            continue
        pattern = os.path.join(log_dir, channel[1:] + '.log.*')
        for filename in glob.glob(pattern):
            messages(i + 1, channel, filename)
    print '</sphinx:docset>'
예제 #11
0
def get_default_channel():
    return util.irc_channels(current_app.config['IRC_CHANNELS'])[0]
예제 #12
0
def get_default_channel():
    return util.irc_channels(current_app.config['IRC_CHANNELS'])[0]