forked from aylanonsense/ncua-gov-aggregator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cu_utils.py
55 lines (47 loc) · 1.24 KB
/
cu_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os, csv, time
timer = None
def start_timer(s):
global timer
timer = time.clock()
print((s + "...").ljust(80)),
def end_timer():
global timer
print("took %f seconds" % (time.clock() - timer))
def csv_to_dict(filepath):
datafile = open(filepath, 'r')
datareader = csv.reader(datafile)
records = []
headers = None
for row in datareader:
if headers is None:
headers = row
else:
record = {}
for i in range(0, len(headers)):
record[headers[i]] = row[i]
records.append(record)
return records
def is_float(value):
try:
float(value)
return True
except ValueError:
return False
def find_years_of_data():
return [int(x[3:-2]) for x in os.walk("./data").next()[1]]
def generate_credit_union_lookup(years):
cu_lookup = {}
for y in years[::-1]:
for cu in csv_to_dict('data/QCR%i12/foicu.txt' % y):
cu_number = cu['CU_NUMBER']
if cu_number not in cu_lookup:
cu_lookup[cu_number] = { 'CU_NAME': cu['CU_NAME'] }
return cu_lookup
def generate_account_lookup(years):
acct_lookup = {}
for y in years[::-1]:
for acct in csv_to_dict('data/QCR%i12/AcctDesc.txt' % y):
acct_id = acct['Account'].upper()
if acct_id not in acct_lookup:
acct_lookup[acct_id] = { 'ACCT_NAME': acct['AcctName'] }
return acct_lookup