예제 #1
0
 def POST(self):
     f =self.signup_form()
     if not f.validates():
         return render.signup(f)
     else:
         model.sign_up(f.d.username,f.d.email,f.d.password,f.d.sex)
         raise web.seeother('/login')
예제 #2
0
def home_page():
    if request.method == 'GET':
        message = 'Welcome to this website, please sign-up'
        return render_template('home_page.html',message=message)
    elif request.method == 'POST':
        username = request.form["username"]
        password = request.form["password"]
        if username and password:
            model.sign_up(username,password)
            message = 'Signed-up'
            return render_template('home_page.html',message=message)
        else: 
            message = 'Please enter something valid'
            return render_template('home_page.html',message=message)
예제 #3
0
def loggin():
    if request.method == 'GET':
        message = 'Welcome to web trader, time to make some $$'
        return render_template('loggin.html', message=message)
    elif request.method == 'POST':
        username = request.form["username"]
        password = request.form["password"]
        loggin = request.form["loggin"]
        if loggin == "Loggin":
            try:
                session['username'] = model.user_check(password)
                if session['username'] == username:
                    message = session['username']
                    return render_template('homepage.html', message=message)
            except:
                message = "Invalid username. Please try another again or sign up"
                return render_template('loggin.html', message=message)
        else:
            model.sign_up(username, password)
            message = 'Signed-up, now logg in with the same credentials'
            return render_template('loggin.html', message=message)
예제 #4
0
def game_loop():
    start = view.start_up_menu()
    if start == "s":
        (user_name, password) = view.sign_up_menu()
        model.sign_up(user_name, password)
    else:
        (user_name, password) = view.logg_in_menu()
        _id = model.user_check(password)
        print(_id)

    while 1:
        buy_inputs = ['b', 'buy']
        sell_inputs = ['s', 'sell']
        lookup_inputs = ['l', 'lookup', 'look up', 'look-up']
        quote_inputs = ['q', 'quote']
        exit_inputs = ['e', 'exit', 'quit']
        view_inputs = ['v']
        acceptable_inputs = buy_inputs     \
                            +sell_inputs   \
                            +lookup_inputs \
                            +quote_inputs  \
                            +exit_inputs   \
                            +view_inputs
        user_input = view.main_menu()
        if user_input in acceptable_inputs:
            if user_input in buy_inputs:
                balance = model.check_balance(user_name)
                fee = 6.25
                ticker_symbol = view.quote_menu()
                price = model.quote(ticker_symbol)
                trade_volume = view.transaction_menu(balance, ticker_symbol,
                                                     price)
                transaction_cost = (float(trade_volume) * price) + fee
                if transaction_cost <= balance:
                    balance -= transaction_cost
                    model.update_cash(user_name, balance)
                    model.buy(user_name, ticker_symbol, float(trade_volume),
                              float(price))
                    model.buy_holdings(user_name, ticker_symbol,
                                       float(trade_volume), price)
                else:
                    print("Not enough monay")

            elif user_input in sell_inputs:
                ticker_symbol = view.quote_menu()
                price = model.quote(ticker_symbol)
                trade_volume = view.sell_menu()
                owned = model.check_holdings(user_name, ticker_symbol)
                if owned and int(trade_volume) <= owned:
                    model.sell_holdings(user_name, ticker_symbol, trade_volume,
                                        price, owned)

            elif user_input in lookup_inputs:
                return model.lookup(view.lookup_menu())
            elif user_input in quote_inputs:
                return model.quote(view.quote_menu())
            elif user_input in view_inputs:
                users = model.get_users()
                users_list = [
                ]  # this is a list of all the users that currenttly have holdings
                for i in users:
                    users_list.append(i[0])

                users_holdings = [
                ]  # users holdings by tickers but not numbers
                for i in users_list:
                    user_holdings = model.get_holdings(i)
                    a = []
                    for i in user_holdings:
                        a.append(i[0])
                    users_holdings.append(a)

                tickers = [
                ]  # is all the stocks the users, un "set'd" and joinined together
                for i in users_holdings:
                    for j in i:
                        tickers.append(j)
                prices = {
                }  # this has all the prices for all the stocks owned in the holdings
                for i in set(tickers):  #
                    price = model.quote(i)
                    prices[i] = price

                volumes = [
                ]  # a list of lists of amount of stock each of them own
                for i in users_list:
                    volumes.append(model.holdings_volumes(i))
                # print(users_holdings)
                # print(volumes)
                values_final = {}
                for i in range(len(users_holdings)):
                    total = 0
                    for j in range(len(users_holdings[i])):
                        total += (prices[users_holdings[i][j]]) * (
                            volumes[i][j][0])
                    values_final[users_list[i]] = total
                highest = 0
                sorted_words = {}
                while values_final:
                    for i in values_final:
                        if values_final[i] >= highest:
                            highest = values_final[i]
                            word = i
                    sorted_words[word] = highest
                    values_final.pop(i)
                    highest = 0
                for i in sorted_words:
                    print("{} : {}".format(i, sorted_words[i]))
                    # highest = 0
                # while values_final:
                #     for i in range(len(values))
                #     if values[i]

                # need to add total balance
                #work vwamp

            elif user_input in exit_inputs:
                break
예제 #5
0
up_name = form.getvalue("up_name")
up_email = form.getvalue("up_email")
up_passwd = form.getvalue("up_password")
conf_pass = form.getvalue("password_confirm")
in_email = form.getvalue("in_email")
in_passwd = form.getvalue("in_password")
dateTime = datetime.utcnow().strftime('%Y-%m-%d %H:%H:%S')

if conf_pass:
    sign_up = {
        'name': up_name,
        'email': up_email,
        'passwd': up_passwd,
        'date': dateTime
    }
    insertSignUp = model.sign_up(sign_up)
    twitterResponse = json.loads(
        insertSignUp
    )  #json.dumps conver the jason.loads to readable for Serialization
    if twitterResponse['status'] == 200:
        # print "Location:http://localhost/neflix/index.py"
        redirect = """<script>window.location.replace('http://localhost/neflix/movie_list.py')</script>"""
        print(redirect)
    else:
        print(twitterResponse['message'])

else:
    sign_in = {'email': in_email, 'passwd': in_passwd}
    insertSignUp = model.sign_in(sign_in)
    twitterResponse = json.loads(
        insertSignUp