diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-06-16 23:32:24 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-06-16 23:32:24 +0300 |
commit | eb930123454771b80465505579d723c92b3dd84c (patch) | |
tree | 9aeded9c85edc2ae9c00ae904d252558731d93f7 /vk/utils/tracking/db/reader | |
parent | make "last seen" timestamps timezone-aware (diff) | |
download | vk-scripts-eb930123454771b80465505579d723c92b3dd84c.tar.gz vk-scripts-eb930123454771b80465505579d723c92b3dd84c.zip |
refactoring & support more user fields
And a bunch of other minor improvements.
Diffstat (limited to '')
-rw-r--r-- | vk/utils/tracking/db/reader/csv.py | 14 |
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 |