-
Notifications
You must be signed in to change notification settings - Fork 2
/
import_senate_bills.py
87 lines (69 loc) · 2.39 KB
/
import_senate_bills.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
import codecs
from csv import DictReader, excel
import os
from models import *
import re
for f in os.listdir('csvs/'):
if 'Bills.txt' in f:
with codecs.open('csvs/' + f, 'rU', 'UTF-8-SIG') as bill_file:
print f
year = re.search('\d{4}', f).group()
reader = DictReader(bill_file, delimiter='\t')
for row in reader:
bill = Bill(
session = Session.select().where(
Session.year_type_num == 1
, Session.session_type == 'R'
, Session.year == re.search('\d{4}', f).group()
).get()
, bill_string = row['Bill'].strip()
, title = row['Title'].strip()
, lr_number = row['LRNum'].strip()
, description = row['Desc'].strip()
, combine_with = row['BillCombinedWith'].strip()
, effective_date = row['EffDate']
, sponsor_string = row['Sponsor']
, combined_with = row['BillCombinedWith']
)
bill.bill_type = Bill_Type.get(id = bill.bill_string.split()[0])
bill.number = bill.bill_string.split()[1]
bill.sponsor = Assembly_Member.select(
Assembly_Member, Person
).join(
Person
).where(
Person.last_name == bill.sponsor_string
, Assembly_Member.chamber == 'S'
, Assembly_Member.assembly == bill.session.assembly
).get()
print bill.sponsor.person.last_name
# bill.save()
# session = ForeignKeyField(Session, related_name = 'bills')
# bill_type = ForeignKeyField(Bill_Type)
# number = IntegerField()
# bill_string = CharField()
# title = CharField(null = True)
# description = CharField(null = True)
# lr_number = CharField()
# sponsor = ForeignKeyField(Assembly_Member, null = True, related_name = 'sponsored_bills')
# sponsor_string = CharField()
# committee = ForeignKeyField(Committee, null = True)
# effective_date = CharField()
# source_doc = ForeignKeyField(Source_Doc)
# created_date = DateTimeField(default = datetime.now)
# combined_with = CharField(null = True)
# Title:
# Bill: SR 750
# Session: R
# Sponsor: Chappelle-Nadal
# Committee:
# BillCombinedWith:
# LRNum: 1505SR.01I
# Desc: Use of Senate Chamber/21st Century Leadership Academy (5-20-15)
# try:
# Bill.create(**row)
# loop over action files from the csv directory
# insert bill action records
# loop over co-sponsor files from the csv directory
# insert co-sponsor records