def NPOPopulateByCity(city, state): """ Internal function to populate the database with NPO's by city. Takes the name of the city and an state abbreviation, ex. 'CA', 'NY', 'WA' """ city = str(city) # safety dance state = str(state) # safety dance print 'Populating database with Non-Profit Organizations in the city of', city + ',', states[state] if ON_OPENSHIFT: lines = open(os.path.join(os.environ['OPENSHIFT_DATA_DIR'], 'npo', 'irs-pub78.txt'), 'r').readlines() else: lines = open('npo/irs-pub78.txt', 'r').readlines() # Information in format: ein | name | city | state | - | United States | for line in lines: npodata = line.split('|') if npodata[3] == state: if npodata[2] == city: try: npo = Npo.objects.get(ein=npodata[0]) print 'Found NPO :', npo.name, 'skipping.' except Npo.DoesNotExist: npo = Npo(ein=npodata[0], name=npodata[1], city=npodata[2], state=npodata[3], country=npodata[5]) print 'Writing NPO :', npo.name, 'to database.' npo.save()
def NPOPopulateAll(): """ Internal Function to populate the database with the initial NPO information from the IRS pub78 download """ # IRS Tax-Exempt NPO's list http://apps.irs.gov/app/eos/forwardToPub78Download.do # wget http://apps.irs.gov/pub/epostcard/data-download-pub78.zip if ON_OPENSHIFT: lines = open(os.path.join(os.environ['OPENSHIFT_DATA_DIR'], 'npo', 'irs-pub78.txt'), 'r').readlines() else: lines = open('npo/irs-pub78.txt', 'r').readlines() # Information in format: ein | name | city | state | - | United States | for line in lines: npodata = line.split('|') try: npo = Npo.objects.get(ein=npodata[0]) print 'Found NPO :', npo.name, 'skipping.' except Npo.DoesNotExist: npo = Npo(ein=npodata[0], name=npodata[1], city=npodata[2], state=npodata[3], country=npodata[5]) print 'Writing NPO :', npo.name, 'to database.' npo.save()