def register_videos(user_id): """Store video and playlist in video database""" user_obj = crud.check_user_to_playlist_id(user_id) playlist_name = request.form.get("playlist-name") playlist_obj = crud.create_playlist(playlist_name, user_id) playlist_id = playlist_obj.playlist_id video_list = request.form.getlist("video-list") n = 1 video_url_id = [video[n] for video in session["videos"][0]] n = 0 video_title = [video[n] for video in session["videos"][0]] video_duration = session["videos"][2] video_category_name = session["videos"][1] dict_video = { video_url_id[i]: video_title[i] for i in range(len(video_url_id)) } for video_ids in video_list: if video_ids in video_url_id: video_title = dict_video[video_ids] crud.create_video(video_title, video_duration, video_ids, playlist_id) return render_template( "current_playlists.html", user_id=user_id, video_list=video_list, playlist_obj=playlist_obj, user_obj=user_obj, )
os.system('dropdb web_videos') os.system('createdb web_videos') model.connect_to_db(server.app) model.db.create_all() # Create video table's initial data. with open('data/video.json') as f: video_data = json.loads(f.read()) video_in_db = [] for video in video_data: channel_name, web_title, youtube_title= ( video['channel_name'], video['web_title'], video['youtube_title']) db_video = crud.create_video( channel_name, web_title, youtube_title) video_in_db.append(db_video)
os.system('createdb edvid') model.connect_to_db(server.app, 'postgresql:///edvid', echo=False) model.db.create_all() # Load movie data from JSON file with open('videos.json') as f: video_data = json.loads(f.read()) # Create videos, store them in list so we can use them # to create fake activities videos_in_db = [] for video in video_data: link, title, notes = (video['link'], video['title'], video['notes']) db_video = crud.create_video(link, title, notes) videos_in_db.append(db_video) # Create 10 users; each user will link to 3 videos for n in range(10): email = f'user{n}@test.com' # Voila! A unique email! password = '******' user = crud.create_user(email, password) for x in range(3): random_video = choice(videos_in_db) #grade = randint(1, 6) fake_title = f'activity{x}' activity = crud.create_activity(fake_title, user) vidact = crud.create_association(random_video, activity)
os.system('dropdb mediadb') os.system('createdb mediadb') model.connect_to_db(server.app) model.db.create_all() # Create videos/images, store them in list so we can use them # to create fake reactions videos_in_db = [] # for video in sample_data: for video in sample_users.v: video_path, description, date_posted = (video.video_path, video.description, video.date_posted) db_video = crud.create_video(video_path, description, date_posted) videos_in_db.append(db_video) # images_in_db = [] # # for image in sample_data: # # for image in sample_users.i: # image_path, description, user_id= (image.image_path, # image.description, image.user_id) # #BRING BACK DATE POSTEDß # db_image = crud.create_image(image_path, description, user_id) # images_in_db.append(db_image) users_list = []
os.system('dropdb youtube_videos') os.system('createdb youtube_videos') model.connect_to_db(server.app) model.db.create_all() # Create video table's initial data. with open('data/video.json') as f: video_data = json.loads(f.read()) video_in_db = [] for video in video_data: channel_name, video_number, video_title, length_hours, length_minutes, length_seconds, views, release_date, comments, likes, dislikes, description, last_updated = ( video['channel_name'], video['video_number'], video['video_title'], video['length_hours'], video['length_minutes'], video['length_seconds'], video['views'], video['release_date'], video['comments'], video['likes'], video['dislikes'], video['description'], video['last_updated']) db_video = crud.create_video(channel_name, video_number, video_title, length_hours, length_minutes, length_seconds, views, release_date, comments, likes, dislikes, description, last_updated) video_in_db.append(db_video)