diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2014-10-23 15:56:17 +0100 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2015-02-16 18:16:07 +0000 |
commit | c629a6480237d8547e198d96e95707e16dabd738 (patch) | |
tree | 53c23735221214ba63f1a8f14e0d34830e3d4a59 | |
parent | 55166d955e6a29acf7259a8c9635523ec51855b0 (diff) | |
download | znc-log-viewer-c629a6480237d8547e198d96e95707e16dabd738.tar.xz |
Split out classes, config file
-rw-r--r-- | application.cfg | 4 | ||||
-rw-r--r-- | classes.py | 22 | ||||
-rwxr-xr-x | run.py | 55 |
3 files changed, 40 insertions, 41 deletions
diff --git a/application.cfg b/application.cfg new file mode 100644 index 0000000..29e8233 --- /dev/null +++ b/application.cfg @@ -0,0 +1,4 @@ +PORT = 7000 +DEBUG = True +URL = 'https://zlv.localhost' +ZNC_LOG_DIR = '/path/to/znc/logdir' diff --git a/classes.py b/classes.py new file mode 100644 index 0000000..c100cea --- /dev/null +++ b/classes.py @@ -0,0 +1,22 @@ +class Network(): + name = '' + url = '' + channels = [] + def __init__(self, name, url, channels): + self.name = name + self.url = url + self.channels = channels +class Channel(): + name = '' + url = '' + logs = [] + def __init__(self, name, url, logs): + self.name = name + self.url = url + self.logs = logs +class Log(): + name = '' + url = '' + def __init__(self, name, url): + self.name = name + self.url = url @@ -1,31 +1,12 @@ #!/usr/bin/env python from flask import Flask, send_from_directory, render_template, url_for +from classes import Network, Channel, Log from urllib.parse import quote_plus import sys, os -class Network(): - name = '' - url = '' - channels = [] - def __init__(self, name, url, channels): - self.name = name - self.url = url - self.channels = channels -class Channel(): - name = '' - url = '' - logs = [] - def __init__(self, name, url, logs): - self.name = name - self.url = url - self.logs = logs -class Log(): - name = '' - url = '' - def __init__(self, name, url): - self.name = name - self.url = url app = Flask(__name__) +app.config.from_pyfile('application.cfg', silent=True) + app.jinja_env.add_extension('jinja2_highlight.HighlightExtension') app.jinja_env.extend(jinja2_highlight_cssclass = 'codehilite') @@ -36,47 +17,40 @@ def get_files(directory): @app.route('/') def index(): - url = 'https://theos.kyriasis.com:5000' - log_dir = '/home/kyrias/znc_logs' - networks = [] - for network_name in get_files(log_dir): - network_url = '{}/{}'.format(url, network_name) + for network_name in get_files(app.config['ZNC_LOG_DIR']): + network_url = '{}/{}'.format(app.config['URL'], network_name) channels = [] - for channel_name in get_files(os.path.join(log_dir, network_name)): + for channel_name in get_files(os.path.join(app.config['ZNC_LOG_DIR'], network_name)): channel_url = '{}/{}'.format(network_url, quote_plus(channel_name)) channel = Channel(channel_name, channel_url, '') channels += [channel] networks += [Network(network_name, network_url, channels)] - return(render_template('list_networks.html', networks=networks, url=url)) + return(render_template('list_networks.html', networks=networks, url=app.config['URL'])) @app.route('/<network_name>') def get_network(network_name): - url = 'https://theos.kyriasis.com:5000' - network_url = '{}/{}'.format(url, network_name) - log_dir = '/home/kyrias/znc_logs' + network_url = '{}/{}'.format(app.config['URL'], network_name) channels = [] - for channel_name in get_files(os.path.join(log_dir, network_name)): + for channel_name in get_files(os.path.join(app.config['ZNC_LOG_DIR'], network_name)): channel_url = '{}/{}'.format(network_url, quote_plus(channel_name)) channel = Channel(channel_name, channel_url, '') channels += [channel] network = Network(network_name, network_url, channels) - return(render_template('show_network.html', network=network, url=url)) + return(render_template('show_network.html', network=network, url=app.config['URL'])) @app.route('/<network_name>/<channel_name>') def channel_logs(network_name, channel_name): - url = 'https://theos.kyriasis.com:5000' - network_url = '{}/{}'.format(url, network_name) + network_url = '{}/{}'.format(app.config['URL'], network_name) channel_url = '{}/{}'.format(network_url, quote_plus(channel_name)) - log_dir = '/home/kyrias/znc_logs' logs = [] - for log_file in get_files(os.path.join(log_dir, network_name, channel_name)): + for log_file in get_files(os.path.join(app.config['ZNC_LOG_DIR'], network_name, channel_name)): log_url = '{}/{}'.format(channel_url, log_file) log = Log(log_file, log_url) @@ -84,12 +58,11 @@ def channel_logs(network_name, channel_name): channel = Channel(channel_name, channel_url, logs) network = Network(network_name, network_url, [channel]) - return(render_template('show_channel.html', network=network, channel=channel, url=url)) + return(render_template('show_channel.html', network=network, channel=channel, url=app.config['URL'])) @app.route('/<network_name>/<channel_name>/<log_file>') def get_log(network_name, channel_name, log_file): - log_dir = '/home/kyrias/znc_logs' - with open(os.path.join(log_dir, network_name, channel_name, log_file), 'rb') as file: + with open(os.path.join(app.config['ZNC_LOG_DIR'], network_name, channel_name, log_file), 'rb') as file: log = file.read().decode('utf-8', 'ignore') return(render_template('log.html', log=log)) |