Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
import ipdb



ipdb.set_trace()
17 changes: 17 additions & 0 deletions lib/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import typer

app = typer.Typer()

@app.command()
def hello(name: str):
print(f"Hello {name}")

@app.command()
def goodbye(name: str, formal: bool = False):
if formal:
print(f"Goodbye {name}. Have a good day.")
else:
print(f"Bye {name}!")

if __name__ == "__main__":
app()
92 changes: 92 additions & 0 deletions lib/models/City.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

class City:

all_cities = []

def __init__(self, name, concerts=None):
self._name = name
self.concerts = concerts or []

#the getter of city names
@property
def name(self):
return self._name
#to have the user input a city and includes logic to raise errors
@name.setter
def name(self, new_name):
if not isinstance(new_name, str):
raise TypeError("City name must be a string")
if not new_name.strip():
raise ValueError("City name cannot be blank")
if not 2 <= len(new_name) <= 25:
raise ValueError("City name length must be between 2 and 25 characters")
self._name = new_name.strip()
#to show concerts that are in a selected city
def display_concerts(self):
if self.concerts:
print(f"Concerts in {self.name}: ")
for concert in self.concerts:
print(f": {concert}")
else:
print(f"No concerts found in {self.name}")
#creates and added the instance of a city to all cities
@classmethod
def add_city(cls, city_name, concerts=None):
city = cls(city_name, concerts)
cls.all_cities.append(city)

@classmethod
def get_all_cities(cls):
return cls.all_cities

def select_city_and_display_concerts(self):
#User selects a city
city_name = input("Enter the city name: ")
#find the city and display the concerts
found_city = None
for city in City.all_cities:
if city._name.lower() == city_name.lower():
found_city = city
break #if break wasn't used the loop would keep going so this is for performance
if found_city:
found_city.display_concerts()
else:
print("City not found.")


# Add cities with concerts to City.all_cities
# City.add_city("Philadelphia", ["Concert 1", "Concert 2"])
# City.add_city("Pittsburgh", ["Concert 3"])
# City.add_city("Buffalo")
# City.add_city("Orlando", ["Concert 4"])
# City.add_city("San Diego")

# Create an instance of City
#city = City("New York", ["Concert 5", "Concert 6"])



# Call the method to select city and display concerts
city.select_city_and_display_concerts()


#list of all concert but for the city
def concerts(self):
from models.concert import Concert
return [concert for concert in Concert.all if concert.city == self]

concert_list = [concert for concert in Concert.all if concert.venue == self]

return concerts_list if len(concerts_list)> 0 else None


#city band
def bands(self):
return list(set([concert.band for concert in self.concerts()]))

def concert(self, date):
for concert in self.concerts():
if concert.date == date:
return concert
return None

66 changes: 66 additions & 0 deletions lib/models/band.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class Band:
def __init__(self, name, members, genre , home_city):
self.name = name
self.members = members
self.genre = genre
self.home_city = home_city



@property
def name(self):
return self._name

@name.setter
def name(self, name):
if isinstance(name, str) and len(name) > 0:
self._name = name
else:
raise Exception("Band name must be a non-empty string") # Changed ValueError to Exception

@property
def members(self):
return self._members

@members.setter
def members(self, members):
if isinstance(members, list) and len(members) > 0:
self._members = members
else:
raise Exception("Members must be a non-empty list")
@property
def genre (self):
return self._genre

@genre .setter
def genre (self, genre ):
if isinstance(genre , str) and genre in ['male', 'female', 'mixed', 'other']:
self._genre = genre
else:
raise Exception("genre must be 'male', 'female', 'mixed', or 'other'")

@property
def home_city(self):
return self._home_city

@home_city.setter
def home_city(self, home_city):
if isinstance(home_city, str) and len(home_city) > 0 and not hasattr(self, 'hometown'):
self._home_city = home_city
else:
raise Exception("Home city must be a non-empty string")

#


def home_city(self):
return f"The band {self.band.name} is playing a show in their home city, {self.band.home_city}, at {self.venue} on {self.date}."


def concert(self):
from models.concert import Concert
return [concert for concert in Concert.all if concert.band == self]


def city(self):
return list(set([concert.venue for concert in self.concerts()]))
74 changes: 74 additions & 0 deletions lib/models/concert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class Concert:
all = []

def __init__(self, name, date, band, city, ticket_cost):
self.name = name
self.date = date
self.band = band
self.city = city
self.ticket_cost = ticket_cost

Concert.all.append(self)

@property
def date(self):
return self._date

@date.setter
def date(self, date):
if isinstance(date, str) and len(date) > 0:
self._date = date
else:
raise ValueError("Date must be a non-empty string")

@property
def ticket_cost(self):
return self._ticket_cost

@ticket_cost.setter
def ticket_cost(self, ticket_cost):
if isinstance(ticket_cost, dict):
for ticket_type, details in ticket_cost.items():
if not isinstance(ticket_type, str):
raise TypeError("Ticket type must be a string")
if not (isinstance(details, list) and len(details) == 2):
raise TypeError("Details must be a list with two elements: cost and attendance")
cost, attendance = details
if not (isinstance(cost, (int, float)) and cost >= 0):
raise ValueError("Cost must be a non-negative number")
if not (isinstance(attendance, int) and attendance >= 0):
raise ValueError("Attendance must be a non-negative integer")
self._ticket_cost = ticket_cost
else:
raise TypeError("Ticket cost must be a dictionary")



#concert band
#must be of type band
#should be able ti change after the cocert is instantiated

@property
def band(self):
return self._band

@band.setter

def band(self, band):
from models.band import Band
if isinstance(band, Band):
self._band + band
else :
raise Exception("Band must be an instrance of Band class!")

def city(self, City):
from models.City import City
if isinstance(City, City):
self._City = City
else :
raise Exception("Band must be an instrance of Band class!")