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 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))
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) session.add(bid_ashley) session.commit()
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 ade=User(username = '******',password = '******') phil=User(username="******", password="******") jolade=User(username="******", password="******") Baseball= Item(name="Nike",description="sports shoes", seller=ade) bid1=Bid(price=3.00,bidder=phil, item_bid=Baseball) bid2=Bid(price=5.00, bidder=jolade, item_bid=Baseball) Baseball.price=[3.00,5.00] session.add_all([ade, Baseball,phil, jolade, bid1, bid2]) session.commit() print (max(Baseball.price))
from sqlalchemy.orm import sessionmaker from datetime import datetime from tbay import User, Bid, Item engine = create_engine('postgresql://*****:*****@localhost:5432/tbay') Session = sessionmaker(bind=engine) session = Session() # Adding users to the tbay database user1 = User(name="Ruchika", password="******") user2 = User(name="Shilpa", password="******") user3 = User(name="Akanskha", password="******") session.add(user1) session.add(user2) session.add(user3) item1 = Item(name="BallR", description="Red Ball", cost=5.25) item2 = Item(name="BallY", description="Yellow Ball", cost=6.25) item3 = Item(name="BallG", description="Green Ball", cost=7.25) session.add_all([item1, item2, item3]) session.commit() user1.sell = [item1, item2] session.commit() #List the items a user is selling print "Printing items for sale by user1" for sale in user1.sell: print "sale is {}".format(sale.name)
""" 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' shirt.description='A T-Shirt from the U2 1989 World Tour' shirt.user=jenna session.add(shirt) session.commit() """ #make one user auction a baseball
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()
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() baseball.name = "baseball" baseball.description = "a beautiful golden baseball" baseball.seller_id = solange.id session.add(baseball) session.commit() jayzbid = Bid() jayzbid.price = 3
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) ''' 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() #Have each other user place two bids on the baseball ''' bid1 = Bid(price=75.00, bidder=jenna, auction_item=baseball) ''' bid1 = Bid() bid1.price=75.00 bid1.bidder=jenna bid1.item=baseball
from sqlalchemy import Column, Integer, String, Float, DateTime, ForeignKey from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, relationship from sqlalchemy.ext.declarative import declarative_base engine = create_engine("postgresql://codio@localhost:5432/tbay") Session = sessionmaker(bind=engine) session = Session() Base = declarative_base() from tbay import Item, User, Bid user1 = User(username="******", password="******") user2 = User(username="******", password="******") session.add_all([user1, user2]) session.commit() item1 = Item(name="doodad", owner=user1) item2 = Item(name="foodad", owner=user2) session.add_all([item1, item2]) session.commit() bid1 = Bid(price=100.0, bidder_id=user1, item_id=item2) bid2 = Bid(price=200.0, bidder_id=user2, item_id=item1) session.add_all([bid1, bid2]) session.commit()
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)
engine = create_engine('postgresql://localhost:5432/tbay3') Session = sessionmaker(bind=engine) session = Session() Base = declarative_base() from tbay import User, Item, Bid kyle = User(username='******') zach = User(username='******') leigh = User(username='******') session.add_all([kyle, zach, leigh]) session.commit() baseball = Item(name='mlb baseball', owner=kyle) football = Item(name='nfl football', owner=zach) piano = Item(name='grand piano', owner=leigh) session.add_all([baseball, football, piano]) session.commit() bid01 = Bid(price=17.50, bidder=kyle, auction_item=football) bid02 = Bid(price=5175, bidder=zach, auction_item=piano) bid03 = Bid(price=21.25, bidder=leigh, auction_item=football) bid04 = Bid(price=18.75, bidder=zach, auction_item=football) bid05 = Bid(price=27.00, bidder=kyle, auction_item=football) bid06 = Bid(price=5500, bidder=kyle, auction_item=piano) session.add_all([bid01, bid02, bid03, bid04, bid05, bid06]) session.commit()
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 from datetime import datetime #name = Column(String, nullable=False) #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)