aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/vk/utils/tracking/db/writer/csv.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-06-16 15:12:59 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-06-16 15:12:59 +0300
commit95772acbd2676873d1b1c7b2c4a4df0a44c01293 (patch)
tree7272615fb596435978e6d8d2aea4d165ac54b1d1 /vk/utils/tracking/db/writer/csv.py
parenttrack_status.py: move stuff to the package (diff)
downloadvk-scripts-95772acbd2676873d1b1c7b2c4a4df0a44c01293.tar.gz
vk-scripts-95772acbd2676873d1b1c7b2c4a4df0a44c01293.zip
add CSV database reader
Diffstat (limited to '')
-rw-r--r--vk/utils/tracking/db/writer/csv.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/vk/utils/tracking/db/writer/csv.py b/vk/utils/tracking/db/writer/csv.py
index 4594e09..8dc2299 100644
--- a/vk/utils/tracking/db/writer/csv.py
+++ b/vk/utils/tracking/db/writer/csv.py
@@ -3,7 +3,6 @@
# See LICENSE.txt for details.
import csv
-from datetime import datetime
from ..record import Record
@@ -15,25 +14,29 @@ class Writer:
self._fd = open(path, mode)
self._writer = csv.writer(self._fd, lineterminator='\n')
- def _is_valid(self):
+ def __bool__(self):
return self._fd is not None
def __enter__(self):
- if not self._is_valid():
- return None
+ if not self:
+ return self
self._fd.__enter__()
return self
def __exit__(self, *args):
- if self._is_valid():
- self._fd.__exit__(*args)
+ if not self:
+ return
+ self._fd.__exit__(*args)
def flush(self):
- if self._is_valid():
- self._fd.flush()
+ if not self:
+ return
+ self._fd.flush()
def write_record(self, user):
- self._write_row(Record(user).to_list())
+ if not self:
+ return
+ self._write_row(Record.from_user(user).to_row())
self.flush()
def _write_row(self, row):