def add_data_todb(data): # takes the return value of the api_data grid, office_name, station, city, state = data grid_id, grid_x, grid_y, endpoint = (grid['grid_id'], grid['grid_x'], grid['grid_y'], grid['office_endpoint']) station_id, station_name, elev, obs_url = (station['station_id'], station['station_name'], station['elevation'], station['observation']) crud.create_forecast_office(grid_id, office_name, grid_x, grid_y, endpoint) crud.create_station(station_id, station_name, elev, grid_id, obs_url) crud.create_city(city, state, grid_id)
def save_the_date(): """saving race, and city to db, allows users to save race to account""" race_name = request.form.get('race_name') race_date = datetime.strptime(request.form.get('date'), '%Y-%m-%dT%H:%M:%S') race_city = request.form.get('city_name') race_zipcode = request.form.get('zipcode') race_url = request.form.get('race_url') race_description = request.form.get('race_description') race_organization_name = request.form.get('organization_name') signup_status = request.form.get('signup_status') notes = request.form.get('notes') #create a new city to add to db new_city = crud.create_city(race_city, race_zipcode) #create a new race to add to db, using the city that was just created new_race = crud.create_race(race_name, race_date, new_city, race_url, race_description, race_organization_name) current_user_id = session.get('current_user', None) if current_user_id: crud.create_current_race(new_race, current_user_id, signup_status, notes) return "Race has been added!"
def city(): with open('data/cities.json') as f: city_data = json.loads(f.read()) cities_in_db = [] for city in city_data: city_name, country_name, geo_lat, geo_lng = (city['city_name'], city['country_name'], city['geo_lat'], city['geo_lng']) # release_date = datetime.strptime(movie['release_date'], '%Y-%m-%d') db_city = crud.create_city(city_name, country_name, geo_lat, geo_lng) cities_in_db.append(db_city) model.db.session.commit()
races_in_db = [] print('/n/n/n/n/n') print(races_in_db) for race in events: date = race['activityStartDate'] city_name = race['place']['cityName'] zipcode = race['place']['postalCode'] race_url = race['homePageUrlAdr'] race_description = race['assetDescriptions'][0].get('description') organization_name = race['organization']['organizationName'] race_name = race['assetName'] #seeding data into cities table city = crud.create_city(city_name, zipcode) #seeding data into races table race = crud.create_race(race_name, date, city, race_url, race_description, organization_name) races_in_db.append(race) for user in users_in_db: # #choose a race for each user from the list of races saved in races_in_db race = choice(races_in_db) #seeding data into current races table current_race = crud.create_current_race(race, user.user_id,
# **** End of check point **** # Create cities (city objects), store them in a list to add climate data later cities_in_db = [] for city in city_list[1:]: #city is a dictionary & city_list a list of dictionaries city_name, country, iso2, lat, lon, pop = (city['city_ascii'], city['country'], city['iso2'], city['lat'], city['lng'], city['population']) # create a city object db_city = crud.create_city(city_name, country, iso2, lat, lon, pop) cities_in_db.append(db_city) #========= CLIMATE TABLE ================= # Loop over the list of city objects # and create corresponding climate data for city in cities_in_db: # Find the city's continent by looking up iso2 key in the country_continent dict continent = country_continent_dict[city.iso2] city.continent = continent # Associate the city with the right continent via sqlalchemy relationship db.session.commit() # Commit changes # Request 12-month climate data for a given city climate_data = get_climate(city.lat, city.lon) for month_data in climate_data['data']: