Gebretewodros73 / AirBnB_clone_v4

Team project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AirBnB Clone - The Console

The AirBnB Clone project at Holberton School aims to build a simple copy of the AirBnB website (HBnB) with a command-line interface for managing objects.

Functionalities of this command interpreter:

  • Create a new object (ex: a new User or a new Place)
  • Retrieve an object from a file, a database, etc.
  • Perform operations on objects (count, compute stats, etc.)
  • Update attributes of an object
  • Destroy an object

Table of Contents

Environment

This project is interpreted and tested on Ubuntu 14.04 LTS using Python 3 (version 3.4.3).

Installation

  1. Clone this repository:
git clone https://github.com/gebretwodros73/AirBnB_clone_v3.git
  1. Access AirBnb directory:
cd AirBnB_clone_v3
  1. Run the command-line interface (interactively):
./console

and enter commands. 4. Run the command-line interface (non-interactively):

echo "<command>" | ./console.py

File Descriptions

  • console.py - The console contains the entry point of the command interpreter. List of commands this console currently supports:

  • EOF - exits console

  • quit - exits console

  • <emptyline> - overwrites default emptyline method and does nothing

  • create - Creates a new instance of BaseModel, saves it (to the JSON file), and prints the id

  • destroy - Deletes an instance based on the class name and id (save the change into the JSON file).

  • show - Prints the string representation of an instance based on the class name and id.

  • all - Prints all string representations of all instances based or not on the class name.

  • update - Updates an instance based on the class name and id by adding or updating an attribute (save the change into the JSON file).

  • /models/ directory contains classes used for this project:

  • base_model.py - The BaseModel class from which future classes will be derived.

    • def __init__(self, *args, **kwargs) - Initialization of the base model
    • def __str__(self) - String representation of the BaseModel class
    • def save(self) - Updates the attribute updated_at with the current datetime
    • def to_dict(self) - Returns a dictionary containing all keys/values of the instance

Classes inherited from Base Model:

  • amenity.py

  • city.py

  • place.py

  • review.py

  • state.py

  • user.py

  • /models/engine directory contains File Storage class that handles JSON serialization and deserialization:

  • file_storage.py - Serializes instances to a JSON file & deserializes back to instances.

    • def all(self) - Returns the dictionary __objects
    • def new(self, obj) - Sets in __objects the obj with key .id
    • def save(self) - Serializes __objects to the JSON file (path: __file_path)
    • def reload(self) - Deserializes the JSON file to __objects
  • /tests directory contains all unit test cases for this project:

Test files for each class:

Usage

To run the command interpreter, execute ./console in the project directory. You will then be able to use the supported commands to manage objects in the AirBnB website.

Examples of use

vagrantAirBnB_clone$./console.py
(hbnb) help

Documented commands (type help <topic>):
========================================
EOF  all  create  destroy  help  quit  show  update

(hbnb) all MyModel
** class doesn't exist **
(hbnb) create BaseModel
7da56403-cc45-4f1c-ad32-bfafeb2bb050
(hbnb) all BaseModel
[[BaseModel] (7da56403-cc45-4f1c-ad32-bfafeb2bb050) {'updated_at': datetime.datetime(2017, 9, 28, 9, 50, 46, 772167), 'id': '7da56403-cc45-4f1c-ad32-bfafeb2bb050', 'created_at': datetime.datetime(2017, 9, 28, 9, 50, 46, 772123)}]
(hbnb) show BaseModel 7da56403-cc45-4f1c-ad32-bfafeb2bb050
[BaseModel] (7da56403-cc45-4f1c-ad32-bfafeb2bb050) {'updated_at': datetime.datetime(2017, 9, 28, 9, 50, 46, 772167), 'id': '7da56403-cc45-4f1c-ad32-bfafeb2bb050', 'created_at': datetime.datetime(2017, 9, 28, 9, 50, 46, 772123)}
(hbnb) destroy BaseModel 7da56403-cc45-4f1c-ad32-bfafeb2bb050
(hbnb) show BaseModel 7da56403-cc45-4f1c-ad32-bfafeb2bb050
** no instance found **
(hbnb) quit

Bugs

No known bugs at this time.

Author

Tewodros Gebre- Github

Zerihun Mohammed - Github

License

Public Domain. No copy write protection.

About

Team project


Languages

Language:Python 69.4%Language:HTML 18.3%Language:CSS 6.0%Language:JavaScript 5.9%Language:Shell 0.3%