X-Git-Url: https://wylark.com/src/infoex-autowx.git/blobdiff_plain/34a5aa872ba8f4fce7ba5ea6a27ccb2721d860b4..a585efb4e491a6a2dab7df5e858b34fe5235f662:/infoex-autowx.py?ds=inline diff --git a/infoex-autowx.py b/infoex-autowx.py index a4e50a9..ea91bef 100755 --- a/infoex-autowx.py +++ b/infoex-autowx.py @@ -27,6 +27,8 @@ import configparser import csv import datetime import logging +import os +import sys import time from collections import OrderedDict @@ -49,11 +51,24 @@ except: log.addHandler(logging.handlers.SysLogHandler()) parser = OptionParser() -parser.add_option("--config", dest="config", metavar="FILE", help="location of config file") +parser.add_option("--config", + dest="config", + metavar="FILE", + help="location of config file") +parser.add_option("--dry-run", + action="store_true", + dest="dry_run", + default=False, + help="fetch data but don't upload to InfoEx") (options, args) = parser.parse_args() config = configparser.ConfigParser(allow_no_value=False) + +if not options.config: + print("Please specify a configuration file via --config") + sys.exit(1) + config.read(options.config) log.debug('STARTING UP') @@ -224,11 +239,14 @@ with open(infoex['csv_filename'], 'w') as f: writer.writerow(final_data) f.close() -#with open(infoex['csv_filename'], 'rb') as f: -# log.debug("uploading FTP file '%s'" % (infoex['host'])) -# ftp = FTP(infoex['host'], infoex['uuid'], infoex['api_key']) -# ftp.storlines('STOR ' + infoex['csv_filename'], f) -# ftp.close() -# f.close() +if not options.dry_run: + # not a dry run + with open(infoex['csv_filename'], 'rb') as f: + log.debug("uploading FTP file '%s'" % (infoex['host'])) + ftp = FTP(infoex['host'], infoex['uuid'], infoex['api_key']) + ftp.storlines('STOR ' + infoex['csv_filename'], f) + ftp.close() + f.close() + os.remove(infoex['csv_filename']) log.debug('DONE')