Veneer Project need some hints

I’m currently on project Veneer exercise: https://www.codecademy.com/paths/computer-science/tracks/cspath-cumulative-art-marketplace/modules/cspath-veneer/projects/veneer

I really have hard time with this project. With walkthrough video I finish 34 tasks.
Now I’m stuck at 35 task, this is what I need to do!

  • Add a wallet instance variable to clients, update the buying and selling of artworks to also exchange dollar amounts.
  • Create a wishlist for your clients, things that are listed but they’re not sure if they should purchase just yet.
  • Create expiration dates for listings! Have out of date listings automatically removed from the marketplace.

If someone can help me with some tips and hints. I don’t look for code, just some tips where I need to start.

this is code from project

class Art:
  def __init__(self, artist, title, medium, year, owner):
    self.artist = artist
    self.title = title
    self.medium = medium
    self.year = year
    self.owner = owner
    
  def __repr__(self):
      return '{artist}. "{title}". {medium}, {year}. {name}, {location}'.format(artist=self.artist, title=self.title, medium=self.medium, year=self.year, name=self.owner.name, location=self.owner.location)

class Marketplace:
  def __init__(self):
    self.listings = []
    
  def add_listing(self, new_listing):
    self.listings.append(new_listing)
    
  def remove_listing(self,remove_listing):
    self.listings.remove(remove_listing)
    
  def show_listing(self):
    for lists in self.listings:
      print(lists)
   
  
class Client:
  def __init__(self, name, location, is_museum, wallet):
    self.name = name
    self.wallet = wallet
    self.is_museum = is_museum
    if is_museum:
      self.location = location
    else:
      self.location = 'Private Collection'
   
  def sell_artwork(self, artwork, price, wallet):
    if artwork.owner == self:
      new_listing = Listing(artwork, price, self)
      veneer.add_listing(new_listing)
      
  def buy_artwork(self, artwork):
    if artwork.owner != self:
      art_listing = None
      for listing in veneer.listings:
        if listing.art == artwork:
          art_listing = listing
          break
    if art_listing != None:
      art_listing.art.owner = self
      veneer.remove_listing(art_listing)
      
      
class Listing:
  def __init__(self, art, price, seller):
    self.art = art
    self.price = price
    self.seller = seller
  
  def __repr__(self):
    return '{n}, {p}'.format(n=self.art.title, p=self.price)

veneer = Marketplace()


edytta = Client('Edytta Halpirt', None, False, 0)
moma = Client('The MOMA', 'New york', True, 0)

girl_with_mandolin = Art('Picasso, Pablo', 'Girl with a Mandolin (Fanny Tellier)', 1910, 'oil in canvas', edytta)
print(girl_with_mandolin)

edytta.sell_artwork(girl_with_mandolin, '6M (USD)', 100)
veneer.show_listing()
moma.buy_artwork(girl_with_mandolin)
print(girl_with_mandolin)
1 Like

Hey I’m curious about whether you were able to do those extra steps!

I am interested to know too. I add wallet into the construction part of the class. Then, I try to calculate the buying price. Here are some of my code.

class Client:
  def __init__(self, name, location, is_museum, wallet):
    self.name = name
    self.wallet = wallet
    balance = self.wallet
    self.is_museum = is_museum
    if is_museum:
      self.location = location
    else:
      self.location = "Private Collection"
  
  def sell_artwork(self, artwork, price):
    if artwork.owner == self:
      new_listing = Listing(artwork, price, self)
      veneer.add_listing(new_listing)
  
  def buy_artwork(self, artwork):
    if artwork.owner != self:
      art_listing = None
      
      for listing in veneer.listings:
        if listing.art == artwork:
          art_listing = listing
          break
      
      if art_listing != None:
        art_listing.art.owner = self
        veneer.remove_listing(art_listing)
  
 def calculate_buying(self, artwork):
    #calculate money from buying  
    for listing in veneer.listings:
      if listing.art == artwork:
        art_listing = listing
        while self.wallet >= artwork.owner.price:
          self.wallet -= artwork.owner.price
          return self.wallet

The result of calling

print(moma.calculate_buying(girl_with_mandolin)) 
>>None

I got “None” as a result instead of the amount left in the wallet.

Note:

Moma's wallet is 7000000. 
The price of that artwork is 6000000.
In this case, the result is should be 1000000.

Do you have any tips?

This is how I implemented the wallet:

  1. Adding wallet variable to constructor.
  def __init__(self, name, location, is_museum, wallet):
    self.name = name
    self.location = location
    self.is_museum = is_museum
    self.wallet = wallet

Then implementing logic to update the wallet balance after a purchase as follows:

  def buy_artwork(self, artwork):
    if artwork.owner != self:
      for listing in veneer.listings:
        if artwork == listing.art:
        	art_listing = listing
        	artwork.owner = self
        	veneer.remove_listing(art_listing)
        	art_listing.seller.wallet += listing.price
        	self.wallet -= listing.price

I also added a .show_balance method to check someone’s wallet balance:

  def show_balance(self):
    print("{name} has ${balance} left.".format(name=self.name, balance=self.wallet))

Hope this helps.

2 Likes

The last “optional” assignment is to create an expiration date for listings so that they are removed automatically.

I wonder how you could do this. I assume it’s not by using a method, since that would have to be called in order to trigger the removal…

EDIT: got it to work by implementing (among others) the following code, but pretty sure this is not the best way.

  def __init__(self, art, price, seller, expiration_date):
    self.art = art
    self.price = price
    self.seller = seller
    self.expiration_date = datetime.datetime.strptime(expiration_date, "%d %B %Y")

and

for listing in veneer.listings:
  if listing.expiration_date < datetime.datetime.today():
    veneer.remove_listing(listing)
2 Likes

Hi @byteninja93187,

That’s a nice solution.

Here’s a page with lots of information on dates and times: datetime — Basic date and time types.

If you would like to experiment with performing math on dates and times, here’s some raw material that could be adapted and integrated into the project:

import datetime
import time
# set a duration of 8 seconds for a listing
seconds_in_listing = 8
now = datetime.datetime.now()
duration_of_listing = datetime.timedelta(seconds=seconds_in_listing)
time_of_expiration = now + duration_of_listing
# time now
print(now)
# time of expiration
print(time_of_expiration)
while True:
  if datetime.datetime.now() > time_of_expiration:
    print("Listing expired!")
    break
  else:
    print("Listing continues ...")
  time.sleep(5) # sleep for 5 seconds

Output:

2019-06-15 08:42:55.278986
2019-06-15 08:43:03.278986
Listing continues ...
Listing continues ...
Listing expired!
5 Likes

Hey, i did the exact same thing but my wallet are not getting updated, can you help?

Hi Would you mind sharing your full code for this exercise if you still have it? Thanks

Sure, see below.

import datetime

class Art:
def init(self, artist, title, medium, year, owner):
self.artist = artist
self.title = title
self.medium = medium
self.year = year
self.owner = owner

def repr(self):
return “{name}. “{title}”. {year}, {medium}. {owner}, {location}.”.format(name=self.artist, title=self.title, year=self.year, medium = self.medium, owner=self.owner, location = self.owner.location)

class Marketplace:
def init(self):
self.listings =

def add_listing(self, new_listing):
self.listings.append(new_listing)

def remove_listing(self, old_listing):
self.listings.remove(old_listing)

def show_listings(self):
for listing in self.listings:
print(listing)

class Client:
def init(self, name, location, is_museum, wallet):
self.name = name
self.location = location
self.is_museum = is_museum
self.wallet = wallet
self.wishlist =

def repr(self):
return “{name}”.format(name=self.name, wallet=self.wallet)

def add_to_wishlist(self, wishlist_item):
if wishlist_item.owner == self:
print(“You are the owner, stupid!”)
else:
for listing in veneer.listings:
if wishlist_item == listing.art:
self.wishlist.append(listing)

def sell_artwork(self, artwork, price, expiration_date):
if artwork.owner == self:
new_listing = Listing(artwork, price, self, expiration_date)
veneer.add_listing(new_listing)

def show_balance(self):
print("{name} has ${balance} left.".format(name=self.name, balance=self.wallet))

def buy_artwork(self, artwork):
if artwork.owner != self:
for listing in veneer.listings:
if artwork == listing.art:
if self.wallet < listing.price:
print(“Not enough funds available!”)
else:
art_listing = listing
artwork.owner = self
veneer.remove_listing(art_listing)
art_listing.seller.wallet += listing.price
self.wallet -= listing.price

class Listing:
def init(self, art, price, seller, expiration_date):
self.art = art
self.price = price
self.seller = seller
self.expiration_date = datetime.datetime.strptime(expiration_date, “%d %B %Y”)

def repr(self):
return “{art}, ${price}, {expiration_date}”.format(art=self.art.title, price=self.price, expiration_date=self.expiration_date)

veneer = Marketplace()

edytta = Client(“Edytta Halpirt”, “Private Collection”, False, 0)

girl_with_mandolin = Art(“Picasso, Pablo”, “Girl with a Mandolin (Fanny Tellier)”, “oil on canvas”, 1910, edytta)

moma = Client(“The MOMA”, “New York”, True, 6000000)

edytta.sell_artwork(girl_with_mandolin, 6000000, “1 January 2000”)

moma.buy_artwork(girl_with_mandolin)

moma.sell_artwork(girl_with_mandolin, 10000000, “1 January 2000”)

for listing in veneer.listings:
if listing.expiration_date < datetime.datetime.today():
veneer.remove_listing(listing)

veneer.show_listings()
print(datetime.datetime.today())