def main(): # Creating rows for User table user = session.query(User).first() user.username = '******' session.commit() # Creating rows for Item table ball = Item() ball.name = 'ball' ball.description = 'Basketball' ball.start_time = datetime.utcnow session.add(ball) session.commit()
def put(): finished = False while not finished: newuser = User() print "Please enter the name you would like to use for your user name: " newuser.username = raw_input() print "Please enter the password you would like to associate with this account:" newuser.password = raw_input() session.add(newuser) session.commit() print "Would you like to create additional accounts? Y/N: " answer = raw_input() if answer == "n": main()
def bid(): finished = False while not finished: biduser = raw_input( "Please enter the user who wishes to place a bid: ") biduser = session.query(User).filter(User.username == biduser).first() biditem = raw_input("What item would you like to bid on? ") biditem = session.query(Item).filter(Item.itemname == biditem).first() print "what is the about of your bid?" newbid = Bid(price=int(raw_input())) session.add(newbid) biduser.userbids.append(newbid) biditem.item_bids.append(newbid) session.commit() print "would you like to bid on another item? Y/N: " answer = raw_input() if answer == "n": main()
def item(): finished = False while not finished: print "Please enter the user name for the user who would like to enter an item for auction: " username = raw_input() itemuser = session.query(User).filter( User.username == username).first() print "Please enter the name of the item you would llike to put up for auction: " newitem = Item() newitem.itemname = raw_input() print "Enter a description of the item: " newitem.itemdescription = raw_input() itemuser.items.append(newitem) session.commit() print "would you like to add additional items? Y/N: " answer = raw_input() if answer == "n": main()
def main(): # add users beyonce = User(username="******", password="******") ariana = User(username="******", password="******") miley = User(username="******", password="******") session.add_all([beyonce, ariana, miley]) session.commit() # Make one user auction a baseball baseball = Item(name="baseball", description="Baseball from Babe Ruth's first home run", seller=ariana) session.add(baseball) session.commit() print("{} started an auction for {} at {}".format( baseball.seller, baseball.name, baseball.start_time.strftime('%m/%d/%y'))) # Have each other use two bids on the baseball starting_bid = Bid(price=100.00, item=baseball, bidder=ariana) bknowles_bid = Bid(price=150.00, item=baseball, bidder=beyonce) mcyrus_bid = Bid(price=200.00, item=baseball, bidder=miley) bid_list = [bknowles_bid, mcyrus_bid] session.add_all([starting_bid, bknowles_bid, mcyrus_bid]) session.commit() for bid in bid_list: print("{} placed a bid on a {} for {}".format(bid.bidder, bid.item, bid.price)) # Perform a query to find out which user placed the highest bid highest_bid = session.query(Bid).order_by(Bid.price.desc()).first() print("{} had the highest bid at ${}".format(highest_bid.bidder.username, highest_bid.price))
#!/usr/bin/python from tbay import session, Item, User, Bid chris = User() chris.username = "******" chris.password = "******" session.add(chris) session.commit() ashley = User(username = "******", password = "******") session.add(ashley) session.commit() lianna = User(username = "******", password = "******") session.add(lianna) session.commit() baseball = Item() baseball.name = "Giants World Series 2014" baseball.description = "Foul ball in game 2" chris.items.append(baseball) session.add(baseball) session.commit() guitar = Item(name = "Fender", description = "rock out with this electric guitar") ashley.items.append(guitar) session.add(guitar) session.commit() bid_ashley = Bid(price = 5000, item = baseball, bidder = ashley)
from tbay import User, Item, Bid, session from datetime import datetime john = User() john.id = 1 john.username = "******" john.password = "******" session.add(john) session.commit() angela = User() angela.id = 2 angela.username = "******" angela.password = "******" session.add(angela) session.commit() car = Item() car.id = 1 car.name = "honda" car.description = "2005 japanese car in blue" session.add(car) session.commit() bike = Item() bike.id = 2 bike.name = "gt" bike.description = "2012 black bicycle" session.add(bike) session.commit()