def borrow(product_id, lender_id): user_id = session.get("user_id", None) form = BorrowForm(product_id=product_id, lender_id=lender_id, user_id=user_id) if form.validate_on_submit(): borrower_id = user_id lender_id = lender_id product_id = product_id date_wanted = datetime.datetime.strptime(form.start_date.data, "%d-%b-%Y") date_returned_est = datetime.datetime.strptime(form.end_date.data, "%d-%b-%Y") #create query borrow_request = model.History(borrower_id=borrower_id, lender_id=lender_id, product_id=product_id, date_wanted=date_wanted, date_returned_est=date_returned_est) #Add the object to a session and commit it. model.session.add(borrow_request) model.session.commit() return redirect("/dashboard") else: flash("didn't work") library_item = model.session.query( model.Library).filter_by(product_id=product_id).first() print library_item.id return render_template("borrow.html", library_item=library_item, user_id=user_id, lender_id=lender_id, form=form)
def path_transmit(path, fileData): if not session.get("user_id") and \ ((fileData.DownloadLimit is not None and fileData.Downloaded >= fileData.DownloadLimit) or \ (fileData.ExpiresIn is not None and time.time() > fileData.Uploaded + fileData.ExpiresIn)): if fileData.HideAfterLimitExceeded: return render_template("no_such_file.html") return render_template("limit_exceeded.html") fileData.Downloaded = model.Path.Downloaded + 1 geoipISOCode = "-" if app.config.get("ENABLE_GEOIP", False): try: geoipISOCode = addon.geoipGetCountry(request.remote_addr) except: import traceback print traceback.format_exc() db.session.add(model.History(path, request.remote_addr, int(time.time()), request.user_agent.string, request.referrer, geoipISOCode)) db.session.commit() return file.transmit(fileData.ActualName, fileData.File.StoredPath)
return response # Custom filter app.jinja_env.filters["usd"] = usd # Configure session to use filesystem (instead of signed cookies) app.config["SESSION_FILE_DIR"] = mkdtemp() app.config["SESSION_PERMANENT"] = False app.config["SESSION_TYPE"] = "filesystem" Session(app) # Configure CS50 Library to use SQLite database db = SQL("sqlite:///finance.db") Utable = model.User() Stable = model.Stock() Htable = model.History() @app.route("/") @login_required def index(): """Show portfolio of stocks""" # Get some values user_id = session["user_id"] porto = Stable.get_portfolio(user_id) total = 0 total_stocks = 0 # Makes json for portfolio for stock in porto: sym = stock['stock']
x_train = x_train.reshape(x_train.shape[0],48,48,1) x_val = x_val.reshape(x_val.shape[0],48,48,1) datagen = ImageDataGenerator( featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, rotation_range=0, width_shift_range=0.2, height_shift_range=0.2, horizontal_flip=True, vertical_flip=True) datagen.fit(x_train) emotion_classifier = model.vgg() emotion_classifier.summary() history = model.History() tbCallBack = TensorBoard(log_dir=os.path.join('./','logs'), write_graph=True, write_images=False) emotion_classifier.fit_generator(datagen.flow(x_train, y_train, batch_size=100), steps_per_epoch=len(x_train) / 100, epochs=80, validation_data=(x_val,y_val), callbacks=[history, tbCallBack]) dump_history('./',history) emotion_classifier.save('model.h5') score = emotion_classifier.evaluate(x_train,y_train) print ('Train Acc:', score[1])