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 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()
from tbay import User, Item, Bid, session beyonce = User() beyonce.username = "******" beyonce.password = "******" session.add(beyonce) patricia = User(username="******", password="******") session.add(patricia) session.commit() # Returns a list of all of the user objects # Note that user objects won't display very prettily by default - # you'll see their type (User) and their internal identifiers. session.query(User).all() # Returns a list of all of the user objects # Returns the first user session.query(User.username).first() # Finds the user with the primary key equal to 1 session.query(User).get(1) # Returns a list of all of the usernames in ascending order session.query(User.username).order_by(User.username).all() # # Returns the description of all of the basesballs # session.query(Item.description).filter(Item.name == "baseball").all() # Return the item id and description for all baseballs which were created in the past. Remember to import the datetime object: from datetime import datetime
from tbay import User, Item, bid, session Charlie = User(user_name="Cgozalez", password="******") session.add(Charlie) Daniel = User(user_name="Dsmith", password="******") session.add(Daniel) Spec = Item(name="Spec", description="design") session.add(Spec) Blackrain = Item(name="Black Rain", description="cloud") session.add(Blackrain) session.commit() print(session.query(User).all())
from tbay import Item, User, Bid, session #add three users to the database """ jp = User(username="******", password="******") jenna = User(username="******", password="******") jaimie = User(username="******", password="******") """ jp = User() jp.username = "******" jp.password = "******" session.add(jp) session.commit() jenna = User() jenna.username = "******" jenna.password = "******" session.add(jenna) session.commit() baseball = Item() baseball.name='1986 World Series Baseball' baseball.description='A baseball signed by the 1986 NY Mets' baseball.user=jp session.add(baseball) session.commit() shirt = Item() shirt.name='U2 World Tour'
from tbay import User, Item, Bid, session beyonce = User() beyonce.username = "******" beyonce.password = "******" sylvester = User() sylvester.username = "******" sylvester.password = "******" jayz = User() jane.username = "******" jane.password = "******" Base.metadata.create_all(engine) session.add_all([beyonce, sylvester, jayz]) session.commit() baseball = Item() headphones.name = "baseball" headphones.description = "Who wants to play ball? Get your baseball here!" session.add(baseball) session.commit()
from tbay import User, Item, Bid, session beyonce = User() beyonce.username = "******" beyonce.password = "******" beyonce.id = "78" session.add(beyonce) session.commit() jayz = User() jayz.username = "******" jayz.password = "******" jayz.id = "56" session.add(jayz) session.commit() solange = User() solange.username = "******" solange.password = "******" solange.id = "1234" session.add(solange) session.commit() crown = Item() crown.name = "crown" crown.description = "a beautiful crown" crown.seller_id = solange.id session.add(crown) session.commit() baseball = Item()
from tbay import Item, User, Bid, session from sqlalchemy import desc #add three users to the database """ jp = User(username="******", password="******") jenna = User(username="******", password="******") jaimie = User(username="******", password="******") """ jp = User() jp.username = "******" jp.password = "******" session.add(jp) session.commit() jenna = User() jenna.username = "******" jenna.password = "******" session.add(jenna) session.commit() jaimie = User() jaimie.username = "******" jaimie.password = "******" session.add(jaimie) session.commit() #make one user auction a baseball ''' baseball = Item(name='1986 World Series Baseball', description='A baseball signed by the 1986 NY Mets', start_time='', owner=jp)
from tbay import Item, User, Bid, session jp = User() jp.username = "******" jp.password = "******" session.add(jp) session.commit() jenna = User() jenna.username = "******" jenna.password = "******" session.add(jenna) session.commit() toy = Item() toy.name = "boat" toy.user = jp session.add(toy) session.commit() user_jp = session.query(User).filter(User.username == "jpc").first() print(user_jp) print(user_jp.username) print(jp.items) find_users = session.query(User).all() print(find_users)
from tbay import User, Item, Bid, session # Create Larisa larisa = User(username='******', password='******') session.add(larisa) # Create Jesse jesse = User(username='******', password='******') session.add(jesse) # Create Brendan brendan = User(username='******', password='******') session.add(brendan) session.commit() # Add a baseball baseball = Item(name='baseball', description='A very nice baseball indeed', seller=jesse) session.add(baseball) session.commit() # Larisa and Brendan bid lbid = Bid(price=0.20, item=baseball, bidder=larisa) bbid = Bid(price=0.25, item=baseball, bidder=brendan) session.add(lbid) session.add(bbid) session.commit() # Find the highest bid highbid = session.query(Bid).filter(Bid.item == baseball).order_by(Bid.price.desc()).first()
from tbay import User, Item, Bid, session # Create Larisa larisa = User(username='******', password='******') session.add(larisa) # Create Jesse jesse = User(username='******', password='******') session.add(jesse) # Create Brendan brendan = User(username='******', password='******') session.add(brendan) session.commit() # Add a baseball baseball = Item(name='baseball', description='A very nice baseball indeed', seller=jesse) session.add(baseball) session.commit() # Larisa and Brendan bid lbid = Bid(price=0.20, item=baseball, bidder=larisa) bbid = Bid(price=0.25, item=baseball, bidder=brendan) session.add(lbid) session.add(bbid) session.commit() # Find the highest bid
#password = Column(String, nullable=False) Eminem = User(id=2, name="Eminem", password="******") Coldplay = User(id=3, name="Coldplay", password="******") baseballr = Item(id=1, name="baseball", description="Red", start_time=datetime.utcnow()) basebally = Item(id=2, name="baseball", description="Yellow", start_time=datetime.utcnow()) baseballv = Item(id=3, name="baseball", description="Violet", start_time=datetime.utcnow()) session.add(Eminem) session.add(Coldplay) session.add(baseballr) session.add(basebally) session.add(baseballv) session.commit() #id = Column(Integer, primary_key=True) # name = Column(String, nullable=False) # description = Column(String) # start_time = Column(DateTime, default=datetime.utcnow)