Giter Site home page Giter Site logo

airbnab_clone_v2's Introduction

AirBnB Clone - The Console The console is the first segment of the AirBnB project at ALX SOftware Engineering Program that will collectively cover fundamental concepts of higher level programming. The goal of AirBnB project is to eventually deploy our server a simple copy of the AirBnB Website(HBnB). A command interpreter is created in this segment to manage objects for the AirBnB(HBnB) website.

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... Do operations on objects (count, compute stats, etc...) Update attributes of an object Destroy an object Table of Content Environment Installation File Descriptions Usage Examples of use Bugs Authors License Environment This project is interpreted/tested on Ubuntu 14.04 LTS using python3 (version 3.4.3)

Installation Clone this repository: git clone "https://github.com/besthor/AirBnB_clone.git" Access AirBnb directory: cd AirBnB_clone Run hbnb(interactively): ./console and enter command Run hbnb(non-interactively): echo "" | ./console.py File Descriptions console.py - the console contains the entry point of the command interpreter. List of commands this console current supports:

EOF - exits console quit - exits console - overwrites default emptyline method and does nothing create - Creates a new instance ofBaseModel, 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 representation 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 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 JASON 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_models/test_base_model.py - Contains the TestBaseModel and TestBaseModelDocs classes TestBaseModelDocs class:

def setUpClass(cls)- Set up for the doc tests def test_pep8_conformance_base_model(self) - Test that models/base_model.py conforms to PEP8 def test_pep8_conformance_test_base_model(self) - Test that tests/test_models/test_base_model.py conforms to PEP8 def test_bm_module_docstring(self) - Test for the base_model.py module docstring def test_bm_class_docstring(self) - Test for the BaseModel class docstring def test_bm_func_docstrings(self) - Test for the presence of docstrings in BaseModel methods TestBaseModel class:

def test_is_base_model(self) - Test that the instatiation of a BaseModel works def test_created_at_instantiation(self) - Test created_at is a pub. instance attribute of type datetime def test_updated_at_instantiation(self) - Test updated_at is a pub. instance attribute of type datetime def test_diff_datetime_objs(self) - Test that two BaseModel instances have different datetime objects /test_models/test_amenity.py - Contains the TestAmenityDocs class:

def setUpClass(cls) - Set up for the doc tests def test_pep8_conformance_amenity(self) - Test that models/amenity.py conforms to PEP8 def test_pep8_conformance_test_amenity(self) - Test that tests/test_models/test_amenity.py conforms to PEP8 def test_amenity_module_docstring(self) - Test for the amenity.py module docstring def test_amenity_class_docstring(self) - Test for the Amenity class docstring /test_models/test_city.py - Contains the TestCityDocs class:

def setUpClass(cls) - Set up for the doc tests def test_pep8_conformance_city(self) - Test that models/city.py conforms to PEP8 def test_pep8_conformance_test_city(self) - Test that tests/test_models/test_city.py conforms to PEP8 def test_city_module_docstring(self) - Test for the city.py module docstring def test_city_class_docstring(self) - Test for the City class docstring /test_models/test_file_storage.py - Contains the TestFileStorageDocs class:

def setUpClass(cls) - Set up for the doc tests def test_pep8_conformance_file_storage(self) - Test that models/file_storage.py conforms to PEP8 def test_pep8_conformance_test_file_storage(self) - Test that tests/test_models/test_file_storage.py conforms to PEP8 def test_file_storage_module_docstring(self) - Test for the file_storage.py module docstring def test_file_storage_class_docstring(self) - Test for the FileStorage class docstring /test_models/test_place.py - Contains the TestPlaceDoc class:

def setUpClass(cls) - Set up for the doc tests def test_pep8_conformance_place(self) - Test that models/place.py conforms to PEP8. def test_pep8_conformance_test_place(self) - Test that tests/test_models/test_place.py conforms to PEP8. def test_place_module_docstring(self) - Test for the place.py module docstring def test_place_class_docstring(self) - Test for the Place class docstring /test_models/test_review.py - Contains the TestReviewDocs class:

def setUpClass(cls) - Set up for the doc tests def test_pep8_conformance_review(self) - Test that models/review.py conforms to PEP8 def test_pep8_conformance_test_review(self) - Test that tests/test_models/test_review.py conforms to PEP8 def test_review_module_docstring(self) - Test for the review.py module docstring def test_review_class_docstring(self) - Test for the Review class docstring /test_models/state.py - Contains the TestStateDocs class:

def setUpClass(cls) - Set up for the doc tests def test_pep8_conformance_state(self) - Test that models/state.py conforms to PEP8 def test_pep8_conformance_test_state(self) - Test that tests/test_models/test_state.py conforms to PEP8 def test_state_module_docstring(self) - Test for the state.py module docstring def test_state_class_docstring(self) - Test for the State class docstring /test_models/user.py - Contains the TestUserDocs class:

def setUpClass(cls) - Set up for the doc tests def test_pep8_conformance_user(self) - Test that models/user.py conforms to PEP8 def test_pep8_conformance_test_user(self) - Test that tests/test_models/test_user.py conforms to PEP8 def test_user_module_docstring(self) - Test for the user.py module docstring def test_user_class_docstring(self) - Test for the User class docstring Examples of use vagrantAirBnB_clone$./console.py (hbnb) help

Documented commands (type help ):

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.

Second part of Airbnb: MySQL HBNB - The Console This repository contains the initial stage of a student project to build a clone of the AirBnB website. This stage implements a backend interface, or console, to manage program data. Console commands allow the user to create, update, and destroy objects, as well as manage file storage. Using a system of JSON serialization/deserialization, storage is persistent between sessions.

Repository Contents by Project Task Tasks Files Description 0: Authors/README File AUTHORS Project authors 1: Pep8 N/A All code is pep8 compliant 2: Unit Testing /tests All class-defining modules are unittested 3. Make BaseModel /models/base_model.py Defines a parent class to be inherited by all model classes 4. Update BaseModel w/ kwargs /models/base_model.py Add functionality to recreate an instance of a class from a dictionary representation 5. Create FileStorage class /models/engine/file_storage.py /models/_ init _.py /models/base_model.py Defines a class to manage persistent file storage system 6. Console 0.0.1 console.py Add basic functionality to console program, allowing it to quit, handle empty lines and ^D 7. Console 0.1 console.py Update the console with methods allowing the user to create, destroy, show, and update stored data 8. Create User class console.py /models/engine/file_storage.py /models/user.py Dynamically implements a user class 9. More Classes /models/user.py /models/place.py /models/city.py /models/amenity.py /models/state.py /models/review.py Dynamically implements more classes 10. Console 1.0 console.py /models/engine/file_storage.py Update the console and file storage system to work dynamically with all classes update file storage

General Use First clone this repository.

Once the repository is cloned locate the "console.py" file and run it as follows:

/AirBnB_clone$ ./console.py When this command is run the following prompt should appear: (hbnb) This prompt designates you are in the "HBnB" console. There are a variety of commands available within the console program. Commands

  • create - Creates an instance based on given class

  • destroy - Destroys an object based on class and UUID

  • show - Shows an object based on class and UUID

  • all - Shows all objects the program has access to, or all objects of a given class

  • update - Updates existing attributes an object based on class name and UUID

  • quit - Exits the program (EOF will as well) Alternative Syntax Users are able to issue a number of console command using an alternative syntax:

Usage: <class_name>.([[name_arg value_arg]|[kwargs]]) Advanced syntax is implemented for the following commands:

  • all - Shows all objects the program has access to, or all objects of a given class

  • count - Return number of object instances by class

  • show - Shows an object based on class and UUID

  • destroy - Destroys an object based on class and UUID

  • update - Updates existing attributes an object based on class name and UUID

Examples Primary Command Syntax Example 0: Create an object Usage: create <class_name>

(hbnb) create BaseModel (hbnb) create BaseModel 3aa5babc-efb6-4041-bfe9-3cc9727588f8 (hbnb)
Example 1: Show an object Usage: show <class_name> <_id>

(hbnb) show BaseModel 3aa5babc-efb6-4041-bfe9-3cc9727588f8 [BaseModel] (3aa5babc-efb6-4041-bfe9-3cc9727588f8) {'id': '3aa5babc-efb6-4041-bfe9-3cc9727588f8', 'created_at': datetime.datetime(2020, 2, 18, 14, 21, 12, 96959), 'updated_at': datetime.datetime(2020, 2, 18, 14, 21, 12, 96971)} (hbnb)
Example 2: Destroy an object Usage: destroy <class_name> <_id>

(hbnb) destroy BaseModel 3aa5babc-efb6-4041-bfe9-3cc9727588f8 (hbnb) show BaseModel 3aa5babc-efb6-4041-bfe9-3cc9727588f8 ** no instance found ** (hbnb)
Example 3: Update an object Usage: update <class_name> <_id>

(hbnb) update BaseModel b405fc64-9724-498f-b405-e4071c3d857f first_name "person" (hbnb) show BaseModel b405fc64-9724-498f-b405-e4071c3d857f [BaseModel] (b405fc64-9724-498f-b405-e4071c3d857f) {'id': 'b405fc64-9724-498f-b405-e4071c3d857f', 'created_at': datetime.datetime(2020, 2, 18, 14, 33, 45, 729889), 'updated_at': datetime.datetime(2020, 2, 18, 14, 33, 45, 729907), 'first_name': 'person'} (hbnb) Alternative Syntax Example 0: Show all User objects Usage: <class_name>.all()

(hbnb) User.all() ["[User] (99f45908-1d17-46d1-9dd2-b7571128115b) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 34, 92071), 'id': '99f45908-1d17-46d1-9dd2-b7571128115b', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 34, 92056)}", "[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"] Example 1: Destroy a User Usage: <class_name>.destroy(<_id>)

(hbnb) User.destroy("99f45908-1d17-46d1-9dd2-b7571128115b") (hbnb) (hbnb) User.all() (hbnb) ["[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"] Example 2: Update User (by attribute) Usage: <class_name>.update(<_id>, <attribute_name>, <attribute_value>)

(hbnb) User.update("98bea5de-9cb0-4d78-8a9d-c4de03521c30", name "Todd the Toad") (hbnb) (hbnb) User.all() (hbnb) ["[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'name': 'Todd the Toad', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"] Example 3: Update User (by dictionary) Usage: <class_name>.update(<_id>, )

(hbnb) User.update("98bea5de-9cb0-4d78-8a9d-c4de03521c30", {'name': 'Fred the Frog', 'age': 9}) (hbnb) (hbnb) User.all() (hbnb) ["[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'name': 'Fred the Frog', 'age': 9, 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"]

airbnab_clone_v2's People

Contributors

bigmoses042 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.