From cd8a117607f982fe0a6c5f66bc8639274bc9ca02 Mon Sep 17 00:00:00 2001 From: Alexander Vasarab Date: Sat, 20 Jun 2020 14:11:25 -0700 Subject: [PATCH] Improve --dry-run behavior Now the working CSV file (csv_filename in the config file) gets deleted, reducing the trash that the program creates. --- README.md | 5 ++++- infoex-autowx.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 258c70a..4433828 100644 --- 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): -`./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 diff --git a/infoex-autowx.py b/infoex-autowx.py index d6edf5e..ea91bef 100755 --- a/infoex-autowx.py +++ b/infoex-autowx.py @@ -27,6 +27,7 @@ import configparser import csv import datetime import logging +import os import sys import time @@ -239,11 +240,13 @@ with open(infoex['csv_filename'], 'w') as f: 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') -- 2.30.2