read()   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
c 1
b 0
f 0
dl 0
loc 28
rs 7.5384
1
"""Reads park millage input data from file."""
2
3
import csv
4
import collections
5
6
import log
7
8
from .common import AttributeDictionary
9
10
11
def read(path):
12
    """Parse a CSV flat file into an ordered dictionary."""
13
14
    parks = collections.OrderedDict()
15
16
    log.info("reading %s...", path)
17
    with open(path, 'r') as csvfile:
18
19
        rows = csv.reader(csvfile)
20
21
        header = None
22
        for row in rows:
23
            if not row:
24
                continue
25
26
            if header is None:
27
                header = row
28
                log.debug("header: %s", header)
29
            else:
30
                log.debug("row: %s", row)
31
                data = AttributeDictionary()
32
                name = row[0]
33
                for index, key in enumerate(header):
34
                    data[key] = row[index]
35
                parks[name] = data
36
37
    log.info("read %s parks", len(parks))
38
    return parks
39