Skip to content

Instantly share code, notes, and snippets.

@sampottinger
Last active December 22, 2015 21:09
Show Gist options
  • Save sampottinger/6531082 to your computer and use it in GitHub Desktop.
Save sampottinger/6531082 to your computer and use it in GitHub Desktop.
Insert data into a local mongodb database using insert as opposed to update.
import pycotracer
import pymongo
client = pymongo.MongoClient()
db = client['tracer-records-db']
for year in range(2000,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.insert_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.insert_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.insert_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