diff options
Diffstat (limited to 'yaksh/file_utils.py')
-rw-r--r-- | yaksh/file_utils.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py index f41c531..0d80b8f 100644 --- a/yaksh/file_utils.py +++ b/yaksh/file_utils.py @@ -2,7 +2,7 @@ import shutil import os import zipfile import tempfile - +import csv def copy_files(file_paths): """ Copy Files to current directory, takes @@ -50,3 +50,30 @@ def extract_files(zip_file, path=None): zip_file.close() return zfiles, extract_path + +def is_csv(document): + try: + try: + content = document.read(1024).decode('utf-8') + except AttributeError: + document.seek(0) + content = document.read(1024) + sniffer = csv.Sniffer() + dialect = sniffer.sniff(content) + document.seek(0) + except (csv.Error, UnicodeDecodeError): + return False + return True + + +def headers_present(dict_reader, headers): + fields = dict_reader.fieldnames + header_fields = set() + for field in fields: + if field.strip() in headers.keys(): + headers[field.strip()] = field + header_fields.add(field.strip()) + if header_fields != set(headers.keys()): + return False + return True + |