summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xrun.py58
-rw-r--r--static/friendly.css61
-rw-r--r--templates/log.html11
3 files changed, 84 insertions, 46 deletions
diff --git a/run.py b/run.py
index 9e3f3d5..f3b6017 100755
--- a/run.py
+++ b/run.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-from flask import Flask, send_from_directory, render_template
+from flask import Flask, send_from_directory, render_template, url_for
from urllib.parse import quote_plus
import sys, os
class Network():
@@ -26,28 +26,8 @@ class Log():
self.url = url
app = Flask(__name__)
-html_tree = '''<html><head><style>
-.tree, .tree ul{
- font: normal normal 14px/20px Helvetica, Arial, sans-serif;
- list-style-type: none; margin-left: 0 0 0 10px;
- padding: 0; position: relative; overflow:hidden;
-}
-.tree li{ margin: 0; padding: 0 12px; position: relative; }
-.tree li::before, .tree li::after{ content: ''; position: absolute; left: 0; }
-
-/* horizontal line on inner list items */
-.tree li::before{ border-top: 1px solid #999; top: 10px; width: 10px; height: 0; }
-
-/* vertical line on list items */
-.tree li:after{ border-left: 1px solid #999; height: 100%; width: 0px; top: -10px; }
-
-/* lower line on list items from the first level because they don't have parents */
-.tree > li::after{ top: 10px; }
-
-/* hide line from the last of the first level list items */
-.tree > li:last-child::after{ display: none; }
-.tree ul:last-child li:last-child:after{ height:20px; }
-</style></head><body><ul class="tree">'''
+app.jinja_env.add_extension('jinja2_highlight.HighlightExtension')
+app.jinja_env.extend(jinja2_highlight_cssclass = 'codehilite')
def get_files(directory):
files = os.listdir(directory)
@@ -106,30 +86,16 @@ def channel_logs(network_name, channel_name):
network = Network(network_name, network_url, [channel])
return(render_template('show_channel.html', network=network, channel=channel, url=url))
-@app.route('/<network>/<channel>/<log_file>')
-def get_log(network, channel, log_file):
+@app.route('/<network_name>/<channel_name>/<log_file>')
+def get_log(network_name, channel_name, log_file):
log_dir = '/home/kyrias/znc_logs'
- return send_from_directory(os.path.join(log_dir, network, channel), log_file)
-
-def main():
- print(arguments)
- if arguments['<network>'] and not arguments['<channel>']:
- channels = get_files(os.path.join(log_dir, arguments['<network>']))
- for c in channels:
- print(c)
-
- elif arguments['<channel>']:
- files = get_files(os.path.join(log_dir, arguments['<network>'], arguments['<channel>']))
- for f in files:
- print(f)
-
- else:
- networks = get_files(log_dir)
- for n in networks:
- print(n)
- channels = get_files(os.path.join(log_dir, n))
- for c in channels:
- print('\t', c)
+ with open(os.path.join(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))
+
+@app.route('/static/<path:filename>')
+def send_static(filename):
+ return send_from_directory('static', filename)
if __name__ == '__main__':
app.run(port=7000, debug=True)
diff --git a/static/friendly.css b/static/friendly.css
new file mode 100644
index 0000000..1f2f18f
--- /dev/null
+++ b/static/friendly.css
@@ -0,0 +1,61 @@
+.codehilite .hll { background-color: #ffffcc }
+.codehilite .c { color: #60a0b0; font-style: italic } /* Comment */
+.codehilite .err { border: 1px solid #FF0000 } /* Error */
+.codehilite .k { color: #007020; font-weight: bold } /* Keyword */
+.codehilite .o { color: #666666 } /* Operator */
+.codehilite .cm { color: #60a0b0; font-style: italic } /* Comment.Multiline */
+.codehilite .cp { color: #007020 } /* Comment.Preproc */
+.codehilite .c1 { color: #60a0b0; font-style: italic } /* Comment.Single */
+.codehilite .cs { color: #60a0b0; background-color: #fff0f0 } /* Comment.Special */
+.codehilite .gd { color: #A00000 } /* Generic.Deleted */
+.codehilite .ge { font-style: italic } /* Generic.Emph */
+.codehilite .gr { color: #FF0000 } /* Generic.Error */
+.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+.codehilite .gi { color: #00A000 } /* Generic.Inserted */
+.codehilite .go { color: #808080 } /* Generic.Output */
+.codehilite .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
+.codehilite .gs { font-weight: bold } /* Generic.Strong */
+.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+.codehilite .gt { color: #0040D0 } /* Generic.Traceback */
+.codehilite .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
+.codehilite .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
+.codehilite .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
+.codehilite .kp { color: #007020 } /* Keyword.Pseudo */
+.codehilite .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
+.codehilite .kt { color: #902000 } /* Keyword.Type */
+.codehilite .m { color: #40a070 } /* Literal.Number */
+.codehilite .s { color: #4070a0 } /* Literal.String */
+.codehilite .na { color: #4070a0 } /* Name.Attribute */
+.codehilite .nb { color: #007020 } /* Name.Builtin */
+.codehilite .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
+.codehilite .no { color: #60add5 } /* Name.Constant */
+.codehilite .nd { color: #555555; font-weight: bold } /* Name.Decorator */
+.codehilite .ni { color: #d55537; font-weight: bold } /* Name.Entity */
+.codehilite .ne { color: #007020 } /* Name.Exception */
+.codehilite .nf { color: #06287e } /* Name.Function */
+.codehilite .nl { color: #002070; font-weight: bold } /* Name.Label */
+.codehilite .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
+.codehilite .nt { color: #062873; font-weight: bold } /* Name.Tag */
+.codehilite .nv { color: #bb60d5 } /* Name.Variable */
+.codehilite .ow { color: #007020; font-weight: bold } /* Operator.Word */
+.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
+.codehilite .mf { color: #40a070 } /* Literal.Number.Float */
+.codehilite .mh { color: #40a070 } /* Literal.Number.Hex */
+.codehilite .mi { color: #40a070 } /* Literal.Number.Integer */
+.codehilite .mo { color: #40a070 } /* Literal.Number.Oct */
+.codehilite .sb { color: #4070a0 } /* Literal.String.Backtick */
+.codehilite .sc { color: #4070a0 } /* Literal.String.Char */
+.codehilite .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
+.codehilite .s2 { color: #4070a0 } /* Literal.String.Double */
+.codehilite .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
+.codehilite .sh { color: #4070a0 } /* Literal.String.Heredoc */
+.codehilite .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
+.codehilite .sx { color: #c65d09 } /* Literal.String.Other */
+.codehilite .sr { color: #235388 } /* Literal.String.Regex */
+.codehilite .s1 { color: #4070a0 } /* Literal.String.Single */
+.codehilite .ss { color: #517918 } /* Literal.String.Symbol */
+.codehilite .bp { color: #007020 } /* Name.Builtin.Pseudo */
+.codehilite .vc { color: #bb60d5 } /* Name.Variable.Class */
+.codehilite .vg { color: #bb60d5 } /* Name.Variable.Global */
+.codehilite .vi { color: #bb60d5 } /* Name.Variable.Instance */
+.codehilite .il { color: #40a070 } /* Literal.Number.Integer.Long */
diff --git a/templates/log.html b/templates/log.html
new file mode 100644
index 0000000..36d6035
--- /dev/null
+++ b/templates/log.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+ <link href="{{ url_for('static', filename='friendly.css') }}" rel="stylesheet" type="text/css">
+ <link rel="stylesheet" type="text/css" href="https://raw.githubusercontent.com/richleland/pygments-css/master/friendly.css">
+</head>
+<body>
+{% highlight 'irc' %}
+{{ log }}
+{% endhighlight %}
+</body>
+</html>