Skip to content

Instantly share code, notes, and snippets.

@mikejcorey
Created August 15, 2014 22:45
Show Gist options
  • Save mikejcorey/c26c7b875e5c370f0e14 to your computer and use it in GitHub Desktop.
Save mikejcorey/c26c7b875e5c370f0e14 to your computer and use it in GitHub Desktop.
Matchmaker, matchmaker, find me valid pairs.
filing_id_amendment_pairs = Filing.objects.all().values('filing_id_raw', 'amend_id', 'filer__pk')
for fa in filing_id_amendment_pairs:
try:
match = CvrLobbyDisclosureCd.objects.get(
filing_id=fa['filing_id_raw'],
amend_id=fa['amend_id']
).values(
'filing_id',
'filer_naml',
'filer_namf',
'lby_actvty',
'rpt_date',
'from_date',
'thru_date',
'amend_id',
)
insert = Report()
insert.filer_id = filing_id_amendment_pairs['filer__pk']
insert.filing_id = match['filing_id']
insert.amend_id = match['amend_id']
insert.filer_lname = match['filer_naml']
insert.filer_fname = match['filer_namf']
insert.lobbying_description = match['lby_actvty']
insert.report_date = match['rpt_date']
insert.report_period_start = match['from_date']
insert.report_period_end = match['thru_date']
#insert.legislative_session = filing['']
i += 1
bulk_records.append(insert)
if i % 5000 == 0:
Report.objects.bulk_create(bulk_records)
print '%s records created ...' % i
bulk_records = []
except:
pass
if len(bulk_records) > 0:
Report.objects.bulk_create(bulk_records)
bulk_records = []
print '%s records created ...' % i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment