示例#1
0
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()
示例#2
0
def query():
    finished = False
    while not finished:
        print "Please see below for a listing of all items up for auction and their bids:"
        print ""
        results = session.query(User).all()
        for result in results:
            print result.username
            for item in result.items:
                print "item =", item.itemname
            for bids in result.userbids:
                print "bids =", bids.biditem.itemname, ": ", bids.price
        print ""
        maxbid = (session.query(Bid).order_by(Bid.price.desc()).limit(1))
        for maxi in maxbid:
            print "And the highest bid is from:", maxi.biduser.username, "with", maxi.price, "dollars!"
            print "Congratulations", maxi.biduser.username, "you are now the proud owner of a shiny new", bids.biditem.itemname, "!"
        print ""
        print "Would you like to run another query? Y/N?: "
        answer = raw_input()
        if answer == "n":
            main()
示例#3
0
文件: main.py 项目: rtuita23/tbay
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()
示例#4
0
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()
示例#5
0
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))
示例#6
0
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()

bid_lianna = Bid(price = 2500, item = baseball, bidder = lianna)
session.add(bid_lianna)
session.commit()

highest_bid = session.query(Bid).filter(Bid.item==baseball).order_by(Bid.price.desc()).first()
#bid = session.query(Bid).(baseball)
#session.query(Bid).filter(price>3000)

print highest_bid.bidder.username
示例#7
0
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
# session.query(Item.id, Item.description).filter(Item.name == "baseball", Item.start_time < datetime.utcnow()).all()
示例#8
0
文件: tbay.py 项目: bharris62/tbay
    user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
    user = relationship('User', backref='bids')


Base.metadata.create_all(engine)

if __name__ == '__main__':
    from tbay import session
    from sqlalchemy import desc

    beyonce = User(username='******', password='******')
    christina = User(username='******', password='******')
    britney = User(username='******', password='******')

    microphone = Item(name="microphone", description="Mika's gold microphone.")

    bids = [
        Bid(price=500.0, user=christina, item=microphone),
        Bid(price=1150.0, user=beyonce, item=microphone),
        Bid(price=200.0, user=christina, item=microphone),
        Bid(price=201.0, user=beyonce, item=microphone),
    ]

    session.add_all([beyonce, christina, britney, microphone] + bids)
    session.commit()

    highest_bid = (session.query(Bid).filter(Bid.item == microphone).order_by(
        desc(Bid.price)).first())

    print(highest_bid.user.username)
    print(highest_bid.item.description)
示例#9
0
文件: text.py 项目: yueyehm/Tbay
from tbay import User, Item, Bid, session

perry = User(name="Perry",password="******")
baseball = Item(name="BaseBall")
perry.items = [baseball]
jesse = User(name="Jesse",password="******")
monica = User(name="Monica",password="******")
bid1 = Bid(price=23.8,bidder=jesse,item=baseball)
bid2 = Bid(price=18.5, bidder=monica,item=baseball)

session.add_all([perry, jesse, monica, baseball, bid1, bid2])
session.commit()
highestBid = session.query(Bid).order_by(Bid.price.desc()).first()
print(highestBid.price, highestBid.bidder.name)
示例#10
0
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())
示例#11
0
文件: main.py 项目: rasalt/tbay
from tbay import User, Item, Bid, session
from datetime import datetime
#name = Column(String, nullable=False)
#password = Column(String, nullable=False)
#beyonce = User(id=1, name = "Beyonce", password = "******")
#session.add(beyonce)
#session.commit()


# Query the database

print("Printing the first user ")
firstuser = session.query(User).first()
print("First: {}".format(firstuser))

print("Printing all the rows from the User table ")
userlist = []
userlist = session.query(User).all()
for user in userlist:
  print("user {}".format(user))

print "Return a user with a user id of 2"
id = 1
user = session.query(User).get(id)
print "User with {} and user is {}".format(id,user)

print "Returning all users orderend by name in ascending order"
userlist = []
userlist = session.query(User.name).order_by(User.name).all()
for user in userlist:
  print("user {}".format(user))
示例#12
0
from tbay import User, Item, Bid, session
from datetime import datetime
#name = Column(String, nullable=False)
#password = Column(String, nullable=False)
#beyonce = User(id=1, name = "Beyonce", password = "******")
#session.add(beyonce)
#session.commit()

# Query the database

print("Printing the first user ")
firstuser = session.query(User).first()
print("First: {}".format(firstuser))

print("Printing all the rows from the User table ")
userlist = []
userlist = session.query(User).all()
for user in userlist:
    print("user {}".format(user))

print "Return a user with a user id of 2"
id = 1
user = session.query(User).get(id)
print "User with {} and user is {}".format(id, user)

print "Returning all users orderend by name in ascending order"
userlist = []
userlist = session.query(User.name).order_by(User.name).all()
for user in userlist:
    print("user {}".format(user))
示例#13
0
bid3 = Bid()
bid3.price=90.00
bid3.bidder=jenna
bid3.item=baseball
session.add(bid3)
session.commit()

bid4 = Bid()
bid4.price=95.00
bid4.bidder=jaimie
bid4.item=baseball
session.add(bid4)
session.commit()


item_list = session.query(Item).all()
print(item_list[0].bids)

for bid in item_list[0].bids:
    print(bid.price)

bids = session.query(Bid).filter(Bid.item == item_list[0]).order_by(desc(Bid.price)).all()

for x in bids:
    print(x.price)
    print(x.bidder.username)

print("The winner is: ")
print(bids[0].bidder.username)

"""
示例#14
0
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)
示例#15
0
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()

print "{} bought a {} ('{}') for {}".format(highbid.bidder.username,
                                            highbid.item.name,
                                            highbid.item.description,
                                            highbid.price)