From 4503c880fdf898de21d609f475d1ac4744975d27 Mon Sep 17 00:00:00 2001 From: Matt Singleton Date: Mon, 16 Oct 2017 19:07:58 -0400 Subject: make the crawl log available via a secret link --- unbiased/html_template/unbiased.css | 6 ++++++ unbiased/html_template/unbiased.jinja.html | 2 +- unbiased/main.py | 16 +++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/unbiased/html_template/unbiased.css b/unbiased/html_template/unbiased.css index dc99ab7..fbbdad2 100755 --- a/unbiased/html_template/unbiased.css +++ b/unbiased/html_template/unbiased.css @@ -52,6 +52,12 @@ hr { color: #cc6; } +#timestamp a { + color: inherit; + text-decoration: inherit; + cursor: inherit; +} + #top-stories { max-width: 900px; display: flex; diff --git a/unbiased/html_template/unbiased.jinja.html b/unbiased/html_template/unbiased.jinja.html index 0d191e7..37f0014 100644 --- a/unbiased/html_template/unbiased.jinja.html +++ b/unbiased/html_template/unbiased.jinja.html @@ -15,7 +15,7 @@
diff --git a/unbiased/main.py b/unbiased/main.py index a0caa5e..cf478dc 100755 --- a/unbiased/main.py +++ b/unbiased/main.py @@ -36,10 +36,15 @@ logging_config = { 'maxBytes': 1024 * 1024, 'backupCount': 3, }, + 'web': { + 'class': 'logging.StreamHandler', + 'level': 'INFO', + 'formatter': 'file', + }, }, 'loggers': { 'unbiased': { - 'handlers': ['console', 'file'], + 'handlers': ['console', 'file', 'web'], }, }, 'root': { @@ -64,13 +69,17 @@ def main(): del logging_config['handlers']['file'] if args.debug: logging_config['handlers']['console']['level'] = 'DEBUG' + web_log_stream = io.StringIO() + logging_config['handlers']['web']['stream'] = web_log_stream logging.config.dictConfig(logging_config) crawl_frequency = 600 while True: + web_log_stream.seek(0) + web_log_stream.truncate() logger.info('Starting crawl') start = time.time() - run(args.webroot, args.sources, args.debug) + run(args.webroot, args.sources, web_log_stream, args.debug) finish = time.time() runtime = finish - start sleeptime = crawl_frequency - runtime @@ -81,7 +90,7 @@ def main(): time.sleep(sleeptime) -def run(webroot, source_names, debug_mode=False): +def run(webroot, source_names, web_log_stream, debug_mode=False): logger.debug('Running with webroot="{}" for sources="{}"'.format(webroot, source_names)) @@ -133,6 +142,7 @@ def run(webroot, source_names, debug_mode=False): output_html = buildOutput(top_stories, middle_stories, bottom_stories) output_html = io.BytesIO(output_html.encode('utf8')) files_to_write['index.html'] = output_html + files_to_write['log.txt'] = io.BytesIO(web_log_stream.getvalue().encode('utf8')) write_files(files_to_write, webroot) write_static_files(webroot) -- cgit v1.2.3