From eb930123454771b80465505579d723c92b3dd84c Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 16 Jun 2016 23:32:24 +0300 Subject: refactoring & support more user fields And a bunch of other minor improvements. --- vk/utils/tracking/db/reader/csv.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'vk/utils/tracking/db/reader/csv.py') 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 -- cgit v1.2.3