From 95772acbd2676873d1b1c7b2c4a4df0a44c01293 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 16 Jun 2016 15:12:59 +0300 Subject: add CSV database reader --- vk/utils/tracking/db/reader/csv.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 vk/utils/tracking/db/reader/csv.py (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 new file mode 100644 index 0000000..b66e397 --- /dev/null +++ b/vk/utils/tracking/db/reader/csv.py @@ -0,0 +1,22 @@ +# Copyright 2016 Egor Tensin +# This file is licensed under the terms of the MIT License. +# See LICENSE.txt for details. + +import csv + +from ..record import Record + +class Reader: + def __init__(self, path): + self._fd = open(path) + self._reader = csv.reader(self._fd) + + def __enter__(self): + self._fd.__enter__() + return self + + def __exit__(self, *args): + self._fd.__exit__(*args) + + def __iter__(self): + return map(Record.from_row, self._reader) -- cgit v1.2.3