From 05bb2595cbc6addbf5cdf145545feca5a5838ef9 Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Thu, 23 Oct 2014 14:47:49 +0100 Subject: Initial commit of working Flask app --- run.py | 134 ++++++++++++++++++++++++++++++++++--------- templates/list_networks.html | 30 ++++++++++ templates/show_channel.html | 35 +++++++++++ templates/show_network.html | 31 ++++++++++ 4 files changed, 203 insertions(+), 27 deletions(-) mode change 100644 => 100755 run.py create mode 100644 templates/list_networks.html create mode 100644 templates/show_channel.html create mode 100644 templates/show_network.html diff --git a/run.py b/run.py old mode 100644 new mode 100755 index 1640dc2..9e3f3d5 --- a/run.py +++ b/run.py @@ -1,6 +1,31 @@ -import os +#!/usr/bin/env python +from flask import Flask, send_from_directory, render_template +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 -tree = {} +app = Flask(__name__) html_tree = '''' -with open('out.html', 'w') as file: - file.write(html_tree) + channels += [channel] + + network = Network(network_name, network_url, channels) + return(render_template('show_network.html', network=network, url=url)) + +@app.route('//') +def channel_logs(network_name, channel_name): + url = 'https://theos.kyriasis.com:5000' + network_url = '{}/{}'.format(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)): + log_url = '{}/{}'.format(channel_url, log_file) + log = Log(log_file, log_url) + + logs += [log] + + 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)) + +@app.route('///') +def get_log(network, channel, 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[''] and not arguments['']: + channels = get_files(os.path.join(log_dir, arguments[''])) + for c in channels: + print(c) + + elif arguments['']: + files = get_files(os.path.join(log_dir, arguments[''], arguments[''])) + 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) + +if __name__ == '__main__': + app.run(port=7000, debug=True) +# arguments = docopt(__doc__) +# main() diff --git a/templates/list_networks.html b/templates/list_networks.html new file mode 100644 index 0000000..aed9ee9 --- /dev/null +++ b/templates/list_networks.html @@ -0,0 +1,30 @@ + + + + + + + diff --git a/templates/show_channel.html b/templates/show_channel.html new file mode 100644 index 0000000..a292c7e --- /dev/null +++ b/templates/show_channel.html @@ -0,0 +1,35 @@ + + + + + + + diff --git a/templates/show_network.html b/templates/show_network.html new file mode 100644 index 0000000..b77533c --- /dev/null +++ b/templates/show_network.html @@ -0,0 +1,31 @@ + + + + + + + -- cgit v1.2.3-54-g00ecf