def cities():
    ids = state_ids()
    for state in ids:
        state_data = b.getCities(state)
        
        for c in state_data:
            db.set_cities(
                            state_id = c['state_id'],
                            state_name = c['state_name'],
                            city = c['city'], 
                            best_places_url = c['bp_url']
                         )
        print "imported {}".format(state)
    return
def city_data():
    city_obj = db.get_cities()
    for c in city_obj:
        try:
            c_data = b.getCityData(c.city, c.state_id, c.best_places_url)
        except:
            print "ERROR could not get data for {}".format(c.city)
            continue
        for d in c_data:
            db.set_cities(
                            state_id = d['state_id'],
                            city = d['city'],
                            population = d['population'], 
                            unemployment = d['unemployment'],
                            avg_commute = d['avg_commute'],
                            median_age = d['median_age'],
                            household_size = d['household_size'],
                            median_home_price = d['median_home_price'],
                            msa = d['msa'],
                            zipcodes = d['zipcodes']

                        )
        print "imported {}".format(c.city)
    return