Skip to content

Commit

Permalink
source: csv: Add option for delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
mhash1m authored and pdxjohnny committed Apr 27, 2021
1 parent a4fa4fe commit 64d8797
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dffml/source/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async def dec(self):
CSV_SOURCE_CONFIG_DEFAULT_KEY = "key"
CSV_SOURCE_CONFIG_DEFAULT_tag = "untagged"
CSV_SOURCE_CONFIG_DEFAULT_tag_COLUMN = "tag"
CSV_SOURCE_CONFIG_DEFAULT_DELIMITER = ","
CSV_SOURCE_CONFIG_DEFAULT_LOADFILES_NAME = None
CSV_SOURCE_CONFIG_DEFAULT_NOSTRIP = False

Expand All @@ -51,6 +52,7 @@ class CSVSourceConfig(FileSourceConfig):
key: str = CSV_SOURCE_CONFIG_DEFAULT_KEY
tag: str = CSV_SOURCE_CONFIG_DEFAULT_tag
tagcol: str = CSV_SOURCE_CONFIG_DEFAULT_tag_COLUMN
delimiter: str = CSV_SOURCE_CONFIG_DEFAULT_DELIMITER
loadfiles: List[str] = CSV_SOURCE_CONFIG_DEFAULT_LOADFILES_NAME
nostrip: bool = CSV_SOURCE_CONFIG_DEFAULT_NOSTRIP

Expand Down Expand Up @@ -92,7 +94,9 @@ async def _empty_file_init(self):
return {}

async def read_csv(self, fd, open_file):
dict_reader = csv.DictReader(fd, dialect="strip")
dict_reader = csv.DictReader(
fd, delimiter=self.config.delimiter, dialect="strip"
)
# Record what headers are present when the file was opened
if not self.config.key in dict_reader.fieldnames:
open_file.write_back_key = False
Expand Down

0 comments on commit 64d8797

Please sign in to comment.