def main(args): db = dbMgr() print "Computing query (this may take a moment...)" query = "SELECT I.address from boroughs B, incidents I where B.borough = 'Manhattan' && B.zipcode = I.zip && I.address IS NOT NULL;" db.run_sql(query) results = db.results() for item in results: print item[0] db.close()
def main(args): db = dbMgr() print "Computing query (this may take a moment...)" query = "SELECT B.zipcode, Z.population from boroughs B, zipcodes Z, incidents I where B.borough = 'Manhattan' && B.zipcode = I.zip && B.zipcode = Z.zipcode;" db.run_sql(query) results = db.results() for item in results: print item[0], item[1] db.close()
def main(): db = dbMgr() # Clean out the previous tables... clean_db(db) # Read in and parse all the CSV files. boroughFile = ParseBoroughsCSV() zipFile = ParseZipCodesCSV() incidentsFile = ParseIncidentsCSV() csv_to_db(db, boroughFile, BOROUGHS_TABLE, primary_key="zipcode") csv_to_db(db, zipFile, ZIP_TABLE, primary_key="zipcode") csv_to_db(db, incidentsFile, INCIDENTS_TABLE) db.close()
def main(args): if len(args) > 0: db = dbMgr() boroughName = args[0] if validate_input(boroughName): print "Computing query (this may take a moment...)" query = "SELECT SUM(Z.population), SUM(I.count) from boroughs B, zipcodes Z, incidents I where B.borough = '{0}' && Z.zipcode = B.zipcode && Z.zipcode = I.zip;".format(boroughName) db.run_sql(query) results = db.results() if len(results) > 0: (population, incidents) = results[0] print "Borough: {0}\n Population: {1}\n Incidents: {2}\n Ratio: {3}".format(boroughName, population, incidents, incidents / population) db.close() else: print "Input must be one of: {0}".format(BOROUGH_NAMES) else: print "Error: Invalid input. Must be one of {0}.".format(BOROUGH_NAMES)
def main(args): if len(args) > 0: db = dbMgr() zipInput = args[0] if validate_input(zipInput): query = "select area, population from zipcodes where zipcode={0}".format(zipInput) db.run_sql(query) results = db.results() if len(results) > 0: (area, population) = results[0] print "Zip Code: {0}\n Population: {1}\n Area: {2}\n Population Density: {3}".format(zipInput, population, area, population / area) else: print "No entry for this zip." db.close() else: print "Invalid zip code. Must not contain letters, and must be 5 characters long" else: print "Error: Invalid input. Please enter a zip code."