2021-09-07 09:59:54 +02:00
|
|
|
# standard imports
|
|
|
|
import logging
|
|
|
|
|
|
|
|
logg = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class CSVProcessor:
|
|
|
|
|
2021-09-07 16:46:53 +02:00
|
|
|
def load(self, s):
|
2021-09-07 09:59:54 +02:00
|
|
|
contents = []
|
|
|
|
f = None
|
|
|
|
try:
|
|
|
|
f = open(s, 'r')
|
|
|
|
except FileNotFoundError:
|
|
|
|
return None
|
|
|
|
|
|
|
|
import csv # only import if needed
|
|
|
|
fr = csv.reader(f)
|
2021-09-08 17:17:49 +02:00
|
|
|
|
2021-09-07 09:59:54 +02:00
|
|
|
for r in fr:
|
|
|
|
contents.append(r)
|
2021-09-09 08:40:20 +02:00
|
|
|
f.close()
|
2021-09-07 09:59:54 +02:00
|
|
|
l = len(contents)
|
|
|
|
logg.info('successfully parsed source as csv, found {} records'.format(l))
|
|
|
|
return contents
|
|
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'csv processor'
|