Last active
December 22, 2015 21:09
-
-
Save sampottinger/6531106 to your computer and use it in GitHub Desktop.
Insert TRACER data into a local db using update to avoid duplicate data (checks for equality using recordID field).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pycotracer | |
import pymongo | |
client = pymongo.MongoClient() | |
db = client['tracer-records-db-2'] | |
for year in range(2013,2014): | |
print "fetching tracer records for year",year | |
contrib_data = pycotracer.get_report(year, pycotracer.REPORT_CONTRIB_DATA) | |
print "fetched contribution records from tracer" | |
pycotracer.mongo_aggregator.update_contribution_entries(db, contrib_data) | |
print "saved",len(contrib_data),"ContributionData records" | |
del contrib_data | |
expend_data = pycotracer.get_report(year, pycotracer.REPORT_EXPEND_DATA) | |
print "fetched expenditure records from tracer" | |
pycotracer.mongo_aggregator.update_expenditure_entries(db, expend_data) | |
print "saved",len(expend_data),"ExpenditureData records" | |
del expend_data | |
loan_data = pycotracer.get_report(year, pycotracer.REPORT_LOAN_DATA) | |
print "fetched loan records from tracer" | |
pycotracer.mongo_aggregator.update_loan_entries(db, loan_data) | |
print "saved",len(loan_data),"LoanData records" | |
del loan_data | |
print "finished loading tracer records for all years" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment