Improve --dry-run behavior
authorAlexander Vasarab <alexander@wylark.com>
Sat, 20 Jun 2020 21:11:25 +0000 (14:11 -0700)
committerAlexander Vasarab <alexander@wylark.com>
Sat, 20 Jun 2020 21:11:25 +0000 (14:11 -0700)
Now the working CSV file (csv_filename in the config file) gets deleted,
reducing the trash that the program creates.

README.md
infoex-autowx.py

index 258c70a4cf0c124896a8bfdd033d4dae71ce311b..44338289fb499617d129fcf968832b4f8e019a79 100644 (file)
--- a/README.md
+++ b/README.md
@@ -37,7 +37,10 @@ data into your InfoEx subscriber account.
 To run ad-hoc (be sure to activate the virtual environment, as detailed in the
 Installation section):
 
 To run ad-hoc (be sure to activate the virtual environment, as detailed in the
 Installation section):
 
-`./infoex-autowx.py --config [path/to/config-file.ini]`
+`./infoex-autowx.py --config [path/to/config-file.ini] [--dry-run]`
+
+**NOTE: Specifying --dry-run will also not clean up the generated CSV
+file.** This is so that you can debug any issues more easily.
 
 Here's an example of a crontab(5) with two SNOTEL sites, each of which
 will run once per hour (note that this will activate the virtual environment
 
 Here's an example of a crontab(5) with two SNOTEL sites, each of which
 will run once per hour (note that this will activate the virtual environment
index d6edf5e4cf88db34c7b3a910bf4bbbadf3863cc2..ea91beff5dc256cfde9116457fc71be1fd49ebb4 100755 (executable)
@@ -27,6 +27,7 @@ import configparser
 import csv
 import datetime
 import logging
 import csv
 import datetime
 import logging
+import os
 import sys
 import time
 
 import sys
 import time
 
@@ -239,11 +240,13 @@ with open(infoex['csv_filename'], 'w') as f:
     f.close()
 
 if not options.dry_run:
     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()
     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')
 
 log.debug('DONE')