aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2021-01-28 21:47:42 -0300
committerSilvio Rhatto <rhatto@riseup.net>2021-01-28 21:47:42 -0300
commit5b6dd528366b6792e16099c628066931d8762134 (patch)
treea599edcf9de9274b3880d31756c3336040306b79
parentcaac6a103f1a76a4ec4a096bb569cd7820a0ff14 (diff)
downloadcsv-hasher-5b6dd528366b6792e16099c628066931d8762134.tar.gz
csv-hasher-5b6dd528366b6792e16099c628066931d8762134.tar.bz2
Feat: additional column check
-rwxr-xr-xcsv-hasher.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/csv-hasher.py b/csv-hasher.py
index 6415c7b..bdd9950 100755
--- a/csv-hasher.py
+++ b/csv-hasher.py
@@ -92,14 +92,6 @@ class CsvHasher:
print('CSV file is too small.')
exit (1)
- # Start with and empty file
- try:
- with open(outfile, 'w') as f:
- f.truncate(0)
- except IOError:
- print('Error writing to ' + outfile)
- exit(1)
-
# Holds columns definition
columns = None
@@ -109,6 +101,19 @@ class CsvHasher:
columns = chunk.columns
break
+ # Check for the column
+ if self.args.colname[0] not in columns:
+ print('Column not found: ' + self.args.colname[0])
+ exit (1)
+
+ # Start with an empty file
+ try:
+ with open(outfile, 'w') as f:
+ f.truncate(0)
+ except IOError:
+ print('Error writing to ' + outfile)
+ exit(1)
+
# Initialize progress bar
progress_bar = tqdm(total=nlines) if self.args.progress else False