Beispiel #1
0

def Legislator_Committees(legislator_id, committee):
    complement = {"legislator_id": legislator_id}
    complement.update(committee)
    c.execute(
        '''
        INSERT INTO committees_legislator_committees(legislator_id, committee_id, ad, session, chair)
        VALUES (%(legislator_id)s, %(name)s, %(ad)s, %(session)s, %(chair)s)
        ON CONFLICT (ad, legislator_id, committee_id, session)
        DO UPDATE
        SET chair = %(chair)s
    ''', complement)


conn = db_settings.con()
c = conn.cursor()

f = codecs.open('legislator/no_committees.txt', 'w', encoding='utf-8')
dict_list = json.load(open('data/twly_crawler/data/9/merged.json'))
json_output = []
ideal_term_end_year = {
    '1': 1993,
    '2': 1996,
    '3': 1999,
    '4': 2002,
    '5': 2005,
    '6': 2008,
    '7': 2012,
    '8': 2016,
    '9': 2020
        SELECT %(name)s
        WHERE NOT EXISTS (SELECT 1 FROM committees_committees WHERE name = %(name)s)
    ''', committees)

def Legislator_Committees(legislator_id, committee):
    complement = {"legislator_id": legislator_id}
    complement.update(committee)
    c.execute('''
        INSERT INTO committees_legislator_committees(legislator_id, committee_id, ad, session, chair)
        VALUES (%(legislator_id)s, %(name)s, %(ad)s, %(session)s, %(chair)s)
        ON CONFLICT (ad, legislator_id, committee_id, session)
        DO UPDATE
        SET chair = %(chair)s
    ''', complement)

conn = db_settings.con()
c = conn.cursor()

f = codecs.open('legislator/no_committees.txt', 'w', encoding='utf-8')
dict_list = json.load(open('data/twly_crawler/data/9/merged.json'))
json_output = []
ideal_term_end_year = {'1': 1993, '2': 1996, '3': 1999, '4': 2002, '5': 2005, '6': 2008, '7': 2012, '8': 2016, '9': 2020}
for legislator in dict_list:
    legislator['uid'] = get_or_create_uid(legislator)
    legislator_origin = legislator.copy()
    json_output.append(legislator_origin)
    legislator = ly_common.normalize_person(legislator)
    legislator['elected_party'] = legislator.get('elected_party', legislator['party'])
    Legislator(legislator)
    LegislatorDetail(legislator['uid'], legislator, ideal_term_end_year[str(legislator['ad'])])
    legislator_id = ly_common.GetLegislatorDetailId(c, legislator['uid'], legislator['ad'])