]> gitweb.fluxo.info Git - csv-hasher.git/commitdiff
Feat: additional column check
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 29 Jan 2021 00:47:42 +0000 (21:47 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 29 Jan 2021 00:47:42 +0000 (21:47 -0300)
csv-hasher.py

index 6415c7b55d17a1df3ff43405e751e56cd84b437f..bdd9950acae68b1c64f03905040f6f236dc0ce5d 100755 (executable)
@@ -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