Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address-Book is added #1140

Closed
Closed
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
22 changes: 22 additions & 0 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -733,3 +733,25 @@ boxoffice = imdb.BoxOffice()
| Methods | Details |
| --------------- | ------------------------------------------------------------------------------- |
| `.top_movies()` | Returns the top box office movies, weekend and total gross, and weeks released. |


### AddressBook

```python
from address_book import AddressBook
```

Create an instance of `AddressBook` class

```python
book = AddressBook()
```

| Method | Details |
| ----------------------------- | ------------------------------------------------------------------------------------------------- |
| `add_contact(name, phone, email)` | Adds a new contact with the provided name, phone, and email. |
| `delete_contact(name)` | Deletes the contact with the provided name. |
| `update_contact(name, phone, email)` | Updates the contact details for the provided name. |
| `get_contact(name)` | Retrieves the contact details for the provided name. |
| `list_contacts()` | Returns a list of all contacts in the address book. |
---
51 changes: 51 additions & 0 deletions src/scrape_up/Address-Book/Address-Book.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import json


class AddressBook:
"""
A class to manage an address book.

Create an instance of `AddressBook` class
```python
book = AddressBook()
```

| Method | Details |
| --------------------- | ----------------------------------------------------------------------------------------------- |
| `add_contact(name, phone, email)` | Adds a new contact with the provided name, phone, and email. |
| `delete_contact(name)` | Deletes the contact with the provided name. |
| `update_contact(name, phone, email)` | Updates the contact details for the provided name. |
| `get_contact(name)` | Retrieves the contact details for the provided name. |
| `list_contacts()` | Returns a list of all contacts in the address book. |
---
"""

def __init__(self):
self.contacts = {}

def add_contact(self, name, phone, email):
self.contacts[name] = {'phone': phone, 'email': email}
return f"Contact {name} added."

def delete_contact(self, name):
if name in self.contacts:
del self.contacts[name]
return f"Contact {name} deleted."
else:
return f"Contact {name} not found."

def update_contact(self, name, phone=None, email=None):
if name in self.contacts:
if phone:
self.contacts[name]['phone'] = phone
if email:
self.contacts[name]['email'] = email
return f"Contact {name} updated."
else:
return f"Contact {name} not found."

def get_contact(self, name):
return self.contacts.get(name, f"Contact {name} not found.")

def list_contacts(self):
return self.contacts
3 changes: 3 additions & 0 deletions src/scrape_up/Address-Book/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .address_book import AddressBook

__all__ = ["AddressBook"]