Implement dry run functionality
authorAlexander Vasarab <alexander@wylark.com>
Sat, 20 Jun 2020 04:36:19 +0000 (21:36 -0700)
committerAlexander Vasarab <alexander@wylark.com>
Sat, 20 Jun 2020 04:36:19 +0000 (21:36 -0700)
infoex-autowx.py

index 4f6c9dc4e3b763bf8075add06f287af6c501bc3c..d6edf5e4cf88db34c7b3a910bf4bbbadf3863cc2 100755 (executable)
@@ -27,6 +27,7 @@ import configparser
 import csv
 import datetime
 import logging
+import sys
 import time
 
 from collections import OrderedDict
@@ -49,11 +50,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 +238,12 @@ 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:
+    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()
 
 log.debug('DONE')