aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/vk/tracking/db/backend
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vk/tracking/db/backend/csv.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/vk/tracking/db/backend/csv.py b/vk/tracking/db/backend/csv.py
index e607774..5b2cc7d 100644
--- a/vk/tracking/db/backend/csv.py
+++ b/vk/tracking/db/backend/csv.py
@@ -4,23 +4,20 @@
# Distributed under the MIT License.
from collections.abc import Iterable
-import csv
+from ..io import InputReaderCSV, OutputWriterCSV
from ..record import Record
from ..timestamp import Timestamp
class Writer:
def __init__(self, fd):
- self._fd = fd
- self._writer = csv.writer(fd, lineterminator='\n')
+ self._writer = OutputWriterCSV(fd)
def on_initial_status(self, user):
self._write_record(user)
- self._fd.flush()
def on_status_update(self, user):
self._write_record(user)
- self._fd.flush()
def on_connection_error(self, e):
pass
@@ -28,10 +25,7 @@ class Writer:
def _write_record(self, user):
if not self:
return
- self._write_row(self._record_to_row(Record.from_user(user)))
-
- def _write_row(self, row):
- self._writer.writerow(row)
+ self._writer.write_row(self._record_to_row(Record.from_user(user)))
@staticmethod
def _record_to_row(record):
@@ -39,7 +33,7 @@ class Writer:
class Reader(Iterable):
def __init__(self, fd):
- self._reader = csv.reader(fd)
+ self._reader = InputReaderCSV(fd)
def __iter__(self):
return map(Reader._record_from_row, self._reader)