This project consists of building a command line interpreter (console) to manipulate data without a visual interface, like in a Shell
- create your data model
- manage (create, update, destroy, etc) objects via a console / command interpreter
- store and persist objects to a file (JSON file)
Our AirBnB clone has been tested on Ubuntu 14.05.5 LTS
Tests done in VirtualBox on Ubuntu via Vagrant(1.9.1)
models/directory contains all classes used for the entire project.models/engine/directory containing File Storage class, handling serialization and deserialization of JSONtests/directory contain all unit teststests/test_modelsdirectory contain all unit tests for classes Amenity, Base Model, City, Place, Review, State, User.tests/test_models/test_engine/directory containing unittest for File Storage class.
console.pythis file is the entry point of the command interpreter.models/base_model.pyis the base class of all models. It contains common elements:- attributes:
id,created_atandupdated_at - methods:
save()andto_json()
- attributes:
models/amenity.py- Class Amenity inherits from BaseModelmodels/city.py- class City, inherits from BaseModelmodels/place.py- class Place, inherits from BaseModelmodels/review.py- class Review, inherits from BaseModelmodels/state.py- class State, inherits from BaseModelmodels/user.py- class User, inherits from BaseModelmodels/engine/file_storage.py- class FileStorage, handling sorage of object - creating new, saving and reloading objects
Location of test files corresponds with the location of program files.
tests/test_console.py- unittest for console.pytests/test_models/test_base_model.py- unittest for base_model.py filetests/test_models/test_engine/test_file_storage.py- unittest for File Storage classtests/test_amenity.py- unittest for Amenity Classtests/test_city.py- unittest for City Classtests/test_place.py- unittest for Place Classtests/test_review.py- unittest for Review Classtests/test_state.py- unittest for State Classtests/test_user.py- unittest for User Class
Amenity ( models/amenity.py ) - Amenity Class which inherits from the class BaseModel. Includes attributes:
name- string format, dafault - empty string
BaseModel (models/base_model.py) - base class that defines all common attributes/methods for other classes.
Attributes include:
id- string, assigned byuuidwhen instance is createdcreate_at- datetime format - assigned when instance is createdupdate_at- datetime format
Methods of class BaseModel:
save(self)- updates public instance attributeupdated_atwith the current datetimeto_json(self)- returns a dictionary containing all keys/values of the instance and the name of the class
City (models/city.py) - class City that inherits from the BaseModel. Contains following attributes:
state_id- string formatname- string format
FileStorage (models/engine/file_storage.py) - class FileStorage - used for serialization of instances to a JSON file and vice versa.
Class attributes:
__file_path- string format - path to JSON file__objects- dictionary - for storing all objects by<class name>.idformat
Class methods:
all(self)- method to return all objectsnew(self, obj)- used to set all objects in the the dictionary with the following key format -<obj class name>.idsave(self)- used to serialize objects to JSON filereload(self)- for deserializing onjects
Place (models/place.py) - class Place, which inherits from the BaseModel class.
Attributes of the class:
city_id- string formatuser_id- string formatname- string formatdescription- string formatnumber_rooms- integer formatnumber_bathrooms- integer formatmax_guest- integer formatprice_by_night- integer formatlatitude- float formatlongitude- float formatamenity_ids- list of strings
Review (models/review.py) - Review class which inherits from BaseModel class.
Attributes of the class:
place_id- string formatuser_id- string formattext- string format
State (models/state.py) - State class which inherits from the BaseModel class. Class attributes:
name- string format
User (models/user.py) - User class that inherits from the BaseModel class.
Class attributes:
email- string formatpassword- string formatfirst_name- string formatlast_name- string format
First step is to clone the repository into your directory:
$ git clone https://github.com/halinav00/AirBnB_clone.git
To run the console, type ./console.py script.
$ ./console.py
Type help for list of commands.
(hbnb) help
Documented commands (type help <topic>):
========================================
EOF all create destroy help quit show update
(hbnb)
Commands include:
create: creates a new instance of model (you need to specify class for the model)show: shows information about a model based on iddestroy: delete modelall: display information about all modelsupdate: updates instance based on name, id and attributequit: exits
Examples of use:
(hbnb) create User
3db5637d-5df4-44cf-a250-ef2b523946e9
(hbnb) show User 3db5637d-5df4-44cf-a250-ef2b523946e9
[User] (3db5637d-5df4-44cf-a250-ef2b523946e9) {'id': '3db5637d-5df4-44cf-a250-ef2b523946e9',
'updated_at': datetime.datetime(2017, 6, 13, 4, 18, 50, 138053), 'created_at':
datetime.datetime(2017, 6, 13, 4, 18, 50, 138027)}
(hbnb) destroy User 3db5637d-5df4-44cf-a250-ef2b523946e9
(hbnb) show User 3db5637d-5df4-44cf-a250-ef2b523946e9
** no instance found **
(hbnb)
If found - call exterminator
- Unittest
- Python packages
- Serialization/Deserialization
*args, **kwargsdatetime
Kimberly Wong - Github || Twitter || email
Halina Veratsennik - Github || Twitter || email
Feedback and contributors are welcomed. Reach out to either authors
