Skip to content

Instantly share code, notes, and snippets.

@sampottinger
Last active December 22, 2015 21:09
Show Gist options
  • Save sampottinger/6531106 to your computer and use it in GitHub Desktop.
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).
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