Last active
December 22, 2015 21:09
-
-
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.
This file contains hidden or 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'] | |
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