def add_suggestion_to_trail_db(): """Adds a selected Suggestion to the db.""" suggestion_id = request.form.get('suggestion_id') suggestion = crud.get_suggestion_by_id(suggestion_id) crud.create_trail(suggestion.name, suggestion.desc, float(suggestion.lat), float(suggestion.long), suggestion.gps, suggestion.length, suggestion.ascent, suggestion.descent, suggestion.difficulty, suggestion.location, suggestion.url, None) return ("Suggestion added to trail db")
def add_edited_suggestion(): """Add an edited suggestion to the trail db. Delete the suggestion from Suggestion db.""" name = request.form.get('name') desc = request.form.get('description') lat = float(request.form.get('lat')) long = float(request.form.get('long')) length = float(request.form.get('length')) ascent = request.form.get('ascent') descent = request.form.get('descent') difficulty = request.form.get('difficulty') location = request.form.get('location') url = request.form.get('url') gps = request.form.get('gps') crud.create_trail(name, desc, lat, long, gps, length, ascent, descent, difficulty, location, url, None) suggestion_id = request.form.get('suggestion-id') crud.delete_suggestion_by_id(suggestion_id) flash("Trail has been added and the suggestion has been deleted.") return redirect('/moderator')
trails_in_db = [] for trail in trail_data['trails']: name = trail.get('name') desc = trail.get('summary') long = trail.get('longitude') lat = trail.get('latitude') gps = None length = trail.get('length') ascent = trail.get('ascent') descent = trail.get('descent') difficulty = trail.get('difficulty') location = trail.get('location') url = trail.get('url') img = trail.get('imgMedium') trail = crud.create_trail(name, desc, lat, long, gps, length, ascent, descent, difficulty, location, url, img) trails_in_db.append(trail) for n in range(10): email = f'user{n}@test.com' # password = '******' # user = crud.create_user(email = email, password = password) user = crud.create_user(email=email) for _ in range(10): crud.create_favorite(user, choice(trails_in_db)) # *************** # Add any data as needed!
# print(search_results) list_of_hiking_dicts= hike_search_results['trails'] #print(list_of_hiking_dicts) trails_in_db=[] for hike in list_of_hiking_dicts: # print(hike) trail_api_id=hike.get('id') trail_name=hike.get('name') latitude=hike.get('latitude') longitude=hike.get('longitude') summary=hike.get('summary') image=hike.get('imgSqSmall') difficulty=hike.get('difficulty') star_rating=hike.get('star') trail_length=hike.get('length') comments='no comments' db_trails=crud.create_trail(trail_api_id,trail_name,latitude,longitude,summary,image,difficulty,star_rating,trail_length,comments) trails_in_db.append(db_trails) print(trails_in_db) # create a hike to add to data base create instances of classes defined in model.py and add it to my database #db.session.add()
from model import db #dbcreate hike_data os.system('dropdb hike_data') os.system('createdb hike_data') model.connect_to_db(server.app) model.db.create_all() # read csv and write to trails_in_db with open('nationalpark.csv', newline='') as csvfile: reader = csv.DictReader(csvfile) trails_in_db = [] for row in reader: # print(row['trail_id']) trail_object = create_trail(row['name'],row['area_name'],row['city_name'],row['state_name'],row['country_name'],row['_geoloc'],row['popularity'],row['length'],row['elevation_gain'],row['difficulty_rating'],row['route_type'],row['visitor_usage'],row['avg_rating'],row['num_reviews'],row['features'],row['activities'],row['units']) trails_in_db.append(trail_object) #fake comments list comments = ['wow!', 'too muddy', 'perfect hike!'] files=os.listdir("static/img/profile_pictures") fnames = ['Melissa', 'Alena', 'Tina', 'Jenny', 'Steph', 'Kristen', 'Emily', 'Deborah', 'Muna', 'Kelsi', 'Samatha', 'Madiha', 'Seale'] lnames = ['Davies', 'Haiser', 'Davis', 'Han', 'Seo', 'Ogamba', 'Sutherland', 'Ong', 'Ainawaer', 'Flatland', 'Gerrity', 'Latif', 'Wong'] user_list = [] #create fake 10 fake users for n in range(10): username = f'Test{n}' password = '******' user_fname = choice(fnames)