aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/vk/utils/tracking/db/reader
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-06-16 23:32:24 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-06-16 23:32:24 +0300
commiteb930123454771b80465505579d723c92b3dd84c (patch)
tree9aeded9c85edc2ae9c00ae904d252558731d93f7 /vk/utils/tracking/db/reader
parentmake "last seen" timestamps timezone-aware (diff)
downloadvk-scripts-eb930123454771b80465505579d723c92b3dd84c.tar.gz
vk-scripts-eb930123454771b80465505579d723c92b3dd84c.zip
refactoring & support more user fields
And a bunch of other minor improvements.
Diffstat (limited to 'vk/utils/tracking/db/reader')
-rw-r--r--vk/utils/tracking/db/reader/csv.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/vk/utils/tracking/db/reader/csv.py b/vk/utils/tracking/db/reader/csv.py
index b66e397..e9c9407 100644
--- a/vk/utils/tracking/db/reader/csv.py
+++ b/vk/utils/tracking/db/reader/csv.py
@@ -2,11 +2,12 @@
# This file is licensed under the terms of the MIT License.
# See LICENSE.txt for details.
+from collections.abc import Iterable
import csv
-from ..record import Record
+from ..record import Record, Timestamp
-class Reader:
+class Reader(Iterable):
def __init__(self, path):
self._fd = open(path)
self._reader = csv.reader(self._fd)
@@ -19,4 +20,11 @@ class Reader:
self._fd.__exit__(*args)
def __iter__(self):
- return map(Record.from_row, self._reader)
+ return map(Reader._record_from_row, self._reader)
+
+ @staticmethod
+ def _record_from_row(row):
+ record = Record(Timestamp.from_string(row[0]))
+ for i in range(len(Record.FIELDS)):
+ record[Record.FIELDS[i]] = row[i + 1]
+ return record