from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base from create import User, Item, Bid engine = create_engine('postgresql://*****:*****@localhost:5432/tbay') Session = sessionmaker(bind=engine) session = Session() Base = declarative_base() bidder1 = User(username='******', password='******') bidder2 = User(username='******', password='******') bidder3 = User(username='******', password='******') session.add_all([bidder1, bidder2, bidder3]) session.commit() auction_item = Item(name='baseball', description='just a baseball', owner_id=bidder1.id) session.add_all([auction_item]) session.commit() bid1 = Bid(price='12.70', bidder_id=bidder1.id, item_id=auction_item.id) bid2 = Bid(price='17.00', bidder_id=bidder2.id, item_id=auction_item.id) bid3 = Bid(price='23.00', bidder_id=bidder3.id, item_id=auction_item.id) bid4 = Bid(price='25.90', bidder_id=bidder1.id, item_id=auction_item.id) session.add_all([bid1, bid2, bid3, bid4]) session.commit()
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base from create import User engine = create_engine('mysql://*****:*****@159.89.180.31/zabbix') Base = declarative_base() Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() new_user = User(username='******', fname='Ahmed', lname='Ali', password='******', email='*****@*****.**', status='True', role='student') session.add(new_user) session.commit()
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base from create import User, Item, Bid engine = create_engine('postgresql://localhost:5432/tbay') Session = sessionmaker(bind=engine) session = Session() Base = declarative_base() bidder1 = User(username='******', password='******') bidder2 = User(username='******', password='******') bidder3 = User(username='******', password='******') session.add_all([bidder1, bidder2, bidder3]) session.commit() auction_item = Item(name='baseball', description='just a baseball', owner_id=bidder1.id) session.add_all([auction_item]) session.commit() bid1 = Bid(price='12.70', bidder_id=bidder1.id, item_id=auction_item.id) bid2 = Bid(price='17.00', bidder_id=bidder2.id, item_id=auction_item.id) bid3 = Bid(price='23.00', bidder_id=bidder3.id, item_id=auction_item.id) bid4 = Bid(price='25.90', bidder_id=bidder1.id, item_id=auction_item.id) session.add_all([bid1, bid2, bid3, bid4]) session.commit()
def main(): print("Hello Welcome to your user list. What is your name?") user_name = input() print(f"Hello {user_name}. what would you like to do?") print('\n') print("New User") print("-" * 10) print("first_name ....") first_name = input() print("last_name ...") last_name = input() print("email ...") email = input() print("username ...") username = input() print("password ...") password = input() new_user = User(first_name, last_name, email, username, password) save_user(new_user) # save_user(create_user(first_name,last_name,email,username,password)) # create and save new user. print('\n') print(f"New User {first_name} {last_name} created") print('\n') while True: print( "Use these short codes : cu - create a new user, du - display user, fu - find a user , np - new password , gp - generate password , dl - delete user, ex -exit the user list " ) short_code = input().lower() # if short_code == 'cu': if short_code == 'du': if display_user(): print("Here is a list of all your user") print('\n') for user in display_user(): print(f"First name.......{user.first_name}") print(f"Last name.......{user.last_name}") print(f" Email.......{user.email}") print('\n') else: print('\n') print("You dont seem to have any user saved yet") print('\n') elif short_code == 'fu': print("Enter the username you want to search for") search_username = input() if check_existing_user(search_username): search_user = find_user(search_username) print(f"{search_user.first_name} {search_user.last_name}") print('-' * 20) print(f"email.......{search_user.email}") print(f"password.......{search_user.password}") else: print("That user does not exist") elif short_code == 'dl': print("Enter the username you want to delete") search_username = input() # print(new_user) if check_existing_user(search_username): # new_user = User(first_name,last_name,email,username,password) del_user(new_user) # print(f"{search_user.first_name} {search_user.last_name}") # print('-' * 20) print(f"Deleted") else: print("That user does not exist") elif short_code == "ex": print("Bye .......") break else: print("I really didn't get that. Please use the short codes")
def display_user(): ''' Function that returns all the saved user ''' return User.display_user()
def create_user(first_name, last_name, email, username, password): ''' Function to create a new user ''' new_user = User(first_name, last_name, email, username, password) return new_user
def check_existing_user(username): ''' Function that check if a user exists with that username and return a Boolean ''' return User.user_exist(username)
def find_user(username): ''' Function that finds a user by username and returns the user ''' return User.find_by_username(username)