From 039f402d6474a41dc6af653db7a60e4529b1d53a Mon Sep 17 00:00:00 2001 From: dspreitz Date: Thu, 22 Sep 2016 08:40:02 +0000 Subject: [PATCH] Added function import_logfile --- README.md | 1 + ogn/gateway/manage.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 2c871c3..9d9ec2f 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ available commands: [gateway] run Run the aprs client. + import_logfiles Import OGN-data from ogn-log-files . [logbook] compute_logbook Compute logbook. diff --git a/ogn/gateway/manage.py b/ogn/gateway/manage.py index 50f0a07..ea5d70a 100644 --- a/ogn/gateway/manage.py +++ b/ogn/gateway/manage.py @@ -40,3 +40,28 @@ def run(aprs_user='anon-dev', logfile='main.log', loglevel='INFO'): client.disconnect() logging.shutdown() + + +@manager.command +def import_logfile(ogn_logfile, logfile='main.log', loglevel='INFO'): + """Import OGN-data from ogn-log-files .""" + + # Check if filename exists + try: + f = open(ogn_logfile, 'r') + except: + print('\nError reading ogn-logfile:', ogn_logfile) + return + + # Enable logging + log_handlers = [logging.StreamHandler()] + if logfile: + log_handlers.append(logging.FileHandler(logfile)) + logging.basicConfig(format=logging_formatstr, level=loglevel, handlers=log_handlers) + + print('Start importing ogn-logfile') + for line in f: + process_beacon(line) + + f.close() + logging.shutdown()