def register(): if request.method == 'GET': return render_template('register.html') if not request.form['email']: flash('email not set properly!') return render_template('register.html') if not request.form['pwd']: flash('pwd not set properly!') return render_template('register.html') if not request.form['nickname']: flash('nickname not set properly') return render_template('register.html') with db_session() as session: if session.query(User).filter_by(email=request.form['email']).count(): flash('user %s already exists, please use another email' % request.form['email']) return render_template('register.html') user = User(email=request.form['email'], pwd=request.form['pwd'], nickname=request.form['nickname']) session.add(user) session.commit() flask_login.login_user(user) return redirect(request.args.get('next') or url_for('index'))
def make_clips(file_loc, clips, vid_id, user_id, socketio): """Makes the designated clips once the file is downloaded""" print "\n\n\n\n\n\n\n\n MAKING CLIPS", file_loc, "\n\n\n\n\n\n\n\n\n" # make a videoFileClip object using temp location path from make-clips route # this is the main video we will make clips from main_vid = VideoFileClip(file_loc) # trim path to remove the file ext clip_name_base = file_loc[0:-4] # save the ext separately # file_ext = file_loc[-4:] file_ext = ".mov" # make a list to hold the new clips so we can upload at the end clips_to_upload = [] scoped_session = db_session() # loop through the clips list and make clips for all the time codes given for clip in clips: # rebind to the db connected clip obj clip = scoped_session.query(Clip).filter(Clip.clip_id == clip.clip_id).first() # get the name and create a temp file path on the server clip_name = clip.clip_name clip_path = 'static/temp/'+clip_name # add to the list of files to upload clips_to_upload.append(clip_path) # create the new subclip new_clip = main_vid.subclip(t_start=clip.start_at, t_end=clip.end_at) # save the clip to our temp file location new_clip.write_videofile(clip_path, codec="libx264") # db_session.remove() #establish session with aws s3session = boto3.session.Session(aws_access_key_id=AWS_ACCESS_KEY, aws_secret_access_key=AWS_SECRET_KEY) s3 = s3session.resource('s3') while len(clips_to_upload) > 0: # pop the clip from the front of the list clip_path = clips_to_upload.pop(0) # if that file exists in the temp folder - upload it if os.path.isfile(clip_path): video_file = clip_path video_name = clip_path.split('/') video_name = video_name[-1] s3.meta.client.upload_file(video_file, BUCKET_NAME, video_name, Callback=file_done(video_name, socketio)) else: #if it wasn't done being written yet - add it back to the list clips_to_upload.append(clip_path)
def login(): if request.method == 'GET': return render_template('login.html') with db_session() as session: try: user = session.query(User).filter_by( email=request.form['email'], pwd=request.form['pwd']).one() except NoResultFound: flash('validate not passed!') return render_template("login.html") flask_login.login_user(user) return redirect(request.args.get('next') or url_for('index'))
def login(): if request.method == 'GET': return render_template('login.html') with db_session() as session: try: user = session.query(User).filter_by( email = request.form['email'], pwd = request.form['pwd']).one() except NoResultFound: flash('validate not passed!') return render_template("login.html") flask_login.login_user(user) return redirect(request.args.get('next') or url_for('index'))
def delete_cliptags(clip_id, tag_id): """Deletes a tag from a case and any associated clips""" scoped_session = db_session() # tag = scoped_session.query(Tag).get(tag_id) print "\n\n\n\n\n\n", tag_id, clip_id, "\n\n\n\n\n" # get the cliptag object to be deleted cliptag = scoped_session.query(ClipTag).filter( ClipTag.clip_id == clip_id, ClipTag.tag_id == tag_id).first() # delete the cliptag scoped_session.delete(cliptag) scoped_session.commit() response = {'tag_id': tag_id, 'clip_id': clip_id} return jsonify(response)
def file_done(vid_name, socketio): """Updates the clip status once upload is complete""" print "\n\n\n\n\n\n\n CLIP READY \n\n\n\n\n\n\n" # start a scoped session scoped_session = db_session() # get the clip by name clip = scoped_session.query(Clip).filter(Clip.clip_name == vid_name).first() clip_id = clip.clip_id # update status and commit the change to the db clip.clip_status = 'Ready' scoped_session.commit() ready_clips = {} ready_clips['clips'] = [clip_id, clip.start_at, clip.end_at] socketio.emit('server update', ready_clips) # close the session db_session.remove()
def update_vid_status(vid_name, socketio): """Updates the video status once upload is complete""" print "\n\n\n\n\n\n\n VIDEO READY \n\n\n\n\n\n\n" # start db session scoped_session = db_session() #get the video based on the name vid = scoped_session.query(Video).filter(Video.vid_name == vid_name).first() vid_id = vid.vid_id #update the status to be ready vid.vid_status = 'Ready' scoped_session.commit() ready_clips = {} ready_clips['clips'] = [vid_id] socketio.emit('server update', ready_clips) # close the scoped session db_session.remove()
def register(): if request.method == 'GET': return render_template('register.html') if not request.form['email']: flash('email not set properly!') return render_template('register.html') if not request.form['pwd']: flash('pwd not set properly!') return render_template('register.html') if not request.form['nickname']: flash('nickname not set properly') return render_template('register.html') with db_session() as session: if session.query(User).filter_by(email=request.form['email']).count(): flash('user %s already exists, please use another email' % request.form['email']) return render_template('register.html') user = User(email=request.form['email'], pwd=request.form['pwd'], nickname=request.form['nickname']) session.add(user) session.commit() flask_login.login_user(user) return redirect(request.args.get('next') or url_for('index'))
def pull_text(clips, vid_id): """Goes to video transcript and pulls relevant text""" # hook up to db scoped_session = db_session() # list to hold all pull tuples all_pulls = [] # get the transcript for the selected video transcript = scoped_session.query(Transcript).filter(Transcript.vid_id == vid_id).first() if transcript: for clip in clips: # if the clip object has a page line num if clip.start_pl is not None: # get the timecodes and text for the request page-line nums pull = find_text_by_page_line(clip.start_pl, clip.end_pl, transcript.text) # a tuple is returned for pull (start_at, end_at, pulled_text) start_at, end_at, pull_text = pull # rebind to the db connected clip obj clip = scoped_session.query(Clip).get(clip.clip_id) clip.start_at = start_at clip.end_at = end_at print "pull clip", clip # make a new pull obj for the db new_pull = TextPull(clip_id=clip.clip_id, pull_text=pull_text) scoped_session.add(new_pull) # add new pull and update clip obj with timecodes from transcript scoped_session.commit() print pull_text # close scoped session db_session.remove()
num_queries_made, total_results = get_listings(HandleListing, MIN_PRICE, MAX_PRICE, prev_crawl_timestamp) total_time = time.time() - start_time crawlhistory = model.CrawlHistory( timestamp=start_time, total_results=total_results, # recent_results=recent_results[0], matched_results=matched_results[0], prev_timestamp=prev_crawl_timestamp, total_time=total_time, num_queries_made=num_queries_made, min_price=MIN_PRICE, max_price=MAX_PRICE, ) db_session.add(crawlhistory) print >> sys.stderr, 'Comitting crawlhistory to DB: ', time.time() db_session.commit() if __name__ == "__main__": if len(sys.argv) > 2: MIN_PRICE = int(sys.argv[1]) MAX_PRICE = int(sys.argv[2]) s = model.db_session() main(s)
print >>sys.stderr, 'Getting listings: ', time.time() num_queries_made, total_results = get_listings(HandleListing, MIN_PRICE, MAX_PRICE, prev_crawl_timestamp) total_time = time.time() - start_time crawlhistory = model.CrawlHistory( timestamp=start_time, total_results=total_results, # recent_results=recent_results[0], matched_results=matched_results[0], prev_timestamp=prev_crawl_timestamp, total_time=total_time, num_queries_made=num_queries_made, min_price=MIN_PRICE, max_price=MAX_PRICE, ) db_session.add(crawlhistory) print >>sys.stderr, 'Comitting crawlhistory to DB: ', time.time() db_session.commit() if __name__ == "__main__": if len(sys.argv) > 2: MIN_PRICE = int(sys.argv[1]) MAX_PRICE = int(sys.argv[2]) s = model.db_session() main(s)
from model import db_session, Users, Songs, Playlists from app import bcrypt # psql -h localhost -d postgres -U postgres -p 5432 -a -q -f create_tables.sql session = db_session() user_1 = Users(id=1, username="******", email="*****@*****.**", first_name="TestName", password=bcrypt.generate_password_hash("admin").decode('utf-8')) song_1 = Songs(id=1, name="1st song", name_of_author="AuthorName", text="qwertyuiop") song_2 = Songs(id=2, name="2nd song", name_of_author="2AuthorName", text="asdfghjkl") song_3 = Songs(id=3, name="3th song", name_of_author="3AuthorName", text="zxcvbnm") playlist_1 = Playlists(id=1, name="1st playlist", is_private=True, owner=user_1, songs=[song_1, song_2])
def user_loader(email): with db_session() as session: return session.query(User).filter_by(email=email).one()
def user_loader(email): with db_session() as session: return session.query(User).filter_by(email=email).one()