Exemple #1
0
def new_basic_user():
    d = dao.databaseAccess()
    id = generate_id()
    now = int(round(time.time()*1000))
    try:
        d.insert("INSERT INTO users (id, date_created) VALUES (?, ?);", (id, now))
        return json.dumps({'success': True, "user_id": id}), 201, {'ContentType': 'application/json'}
    except Error as e:
        return json.dumps({'success': False, "error": e}), 422, {'ContentType': 'application/json'}
Exemple #2
0
"""
portfolio (
name text NOT NULL,
ticker text NOT NULL,
num_stocks real NOT NULL,
cost integer NOT NULL,
buy_date int NOT NULL, 
sell_date int NOT NULL,
sell_price real NOT NULL,
txn_id text NOT NULL,
user_id integer NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);
"""
now = int(round(time.time() * 1000))
d = dao.databaseAccess()


def generate_id():
    return str('TXN' + ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for _ in range(5)))


def buy_stock(name, ticker, num_stocks, price, user_id):
    thisID = generate_id()
    try:
        d.insert(
            """
        INSERT INTO portfolio (name, ticker, num_stocks, cost, buy_date, txn_id, user_id) VALUES 
        (?, ?, ?, ?, ?, ?, ?);""",