aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/vk/tracking/db/backend
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-01-28 02:40:27 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-01-28 02:40:27 +0300
commit1c0e2c13d4f0acbe42e43d886df4f1067506efed (patch)
tree8d76116d718293275315605b66f1466af7d09c27 /vk/tracking/db/backend
parentbin: move file i/o to a separate module (diff)
downloadvk-scripts-1c0e2c13d4f0acbe42e43d886df4f1067506efed.tar.gz
vk-scripts-1c0e2c13d4f0acbe42e43d886df4f1067506efed.zip
vk: move file i/o to a separate module
Diffstat (limited to 'vk/tracking/db/backend')
-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)