summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application.cfg4
-rw-r--r--classes.py22
-rwxr-xr-xrun.py55
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
diff --git a/run.py b/run.py
index f3b6017..4bcac3a 100755
--- a/run.py
+++ b/run.py
@@ -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))