diff --git a/AUTHORS b/AUTHORS index 64b26acdc14..f6155437567 100644 --- a/AUTHORS +++ b/AUTHORS @@ -4,3 +4,4 @@ Jennifer Huang <133@holbertonschool.com> Alexa Orrico <210@holbertonschool.com> Joann Vuong <130@holbertonschool.com> +Uzor Solomon diff --git a/README.md b/README.md index f1d72de6355..7cc83428537 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,10 @@ No known bugs at this time. ## Authors Alexa Orrico - [Github](https://github.com/alexaorrico) / [Twitter](https://twitter.com/alexa_orrico) Jennifer Huang - [Github](https://github.com/jhuang10123) / [Twitter](https://twitter.com/earthtojhuang) +Uzor Solomon Second part of Airbnb: Joann Vuong ## License -Public Domain. No copy write protection. +Public Domain. No copy write protection. + + diff --git a/__pycache__/console.cpython-310.pyc b/__pycache__/console.cpython-310.pyc new file mode 100644 index 00000000000..10e2b221ea1 Binary files /dev/null and b/__pycache__/console.cpython-310.pyc differ diff --git a/console.py b/console.py index 4798f9ac76b..e133363e235 100755 --- a/console.py +++ b/console.py @@ -46,10 +46,10 @@ def _key_value_parser(self, args): else: try: value = int(value) - except: + except Exception: try: value = float(value) - except: + except Exception: continue new_dict[key] = value return new_dict @@ -140,12 +140,12 @@ def do_update(self, arg): if args[2] in integers: try: args[3] = int(args[3]) - except: + except Exception: args[3] = 0 elif args[2] in floats: try: args[3] = float(args[3]) - except: + except Exception: args[3] = 0.0 setattr(models.storage.all()[k], args[2], args[3]) models.storage.all()[k].save() @@ -160,5 +160,6 @@ def do_update(self, arg): else: print("** class doesn't exist **") + if __name__ == '__main__': HBNBCommand().cmdloop() diff --git a/models/__pycache__/__init__.cpython-310.pyc b/models/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 00000000000..46c62a7889a Binary files /dev/null and b/models/__pycache__/__init__.cpython-310.pyc differ diff --git a/models/__pycache__/amenity.cpython-310.pyc b/models/__pycache__/amenity.cpython-310.pyc new file mode 100644 index 00000000000..7a9e03c0a3d Binary files /dev/null and b/models/__pycache__/amenity.cpython-310.pyc differ diff --git a/models/__pycache__/base_model.cpython-310.pyc b/models/__pycache__/base_model.cpython-310.pyc new file mode 100644 index 00000000000..8df8f9d719b Binary files /dev/null and b/models/__pycache__/base_model.cpython-310.pyc differ diff --git a/models/engine/__pycache__/__init__.cpython-310.pyc b/models/engine/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 00000000000..b233856ff05 Binary files /dev/null and b/models/engine/__pycache__/__init__.cpython-310.pyc differ diff --git a/models/engine/__pycache__/file_storage.cpython-310.pyc b/models/engine/__pycache__/file_storage.cpython-310.pyc new file mode 100644 index 00000000000..f4bf6ecea12 Binary files /dev/null and b/models/engine/__pycache__/file_storage.cpython-310.pyc differ diff --git a/models/engine/db_storage.py b/models/engine/db_storage.py index b8e7d291e6f..58ce350813f 100755 --- a/models/engine/db_storage.py +++ b/models/engine/db_storage.py @@ -74,3 +74,28 @@ def reload(self): def close(self): """call remove() method on the private session attribute""" self.__session.remove() + + def get(self, cls, id): + """Get method.""" + if cls not in classes.values(): + return None + + all_cls = models.storage.all(cls) + for value in all_cls.values(): + if (value.id == id): + return value + + return None + + def count(self, cls=None): + """count the number of objects in the storage""" + all_classes = classes.values() + + if not cls: + count = 0 + for clas in all_classes: + count += len(models.storage.all(clas).values()) + else: + count += len(models.storage.all(cls).values()) + + return count diff --git a/models/engine/file_storage.py b/models/engine/file_storage.py index c8cb8c1764d..a2d96eee09c 100755 --- a/models/engine/file_storage.py +++ b/models/engine/file_storage.py @@ -3,6 +3,7 @@ Contains the FileStorage class """ +import models import json from models.amenity import Amenity from models.base_model import BaseModel @@ -55,7 +56,7 @@ def reload(self): jo = json.load(f) for key in jo: self.__objects[key] = classes[jo[key]["__class__"]](**jo[key]) - except: + except Exception: pass def delete(self, obj=None): @@ -68,3 +69,29 @@ def delete(self, obj=None): def close(self): """call reload() method for deserializing the JSON file to objects""" self.reload() + + def get(self, cls, id): + """Get method.""" + + if cls not in classes.values(): + return None + + all_cls = models.storage.all(cls) + for value in all_cls.values(): + if (value.id) == id: + return value + + return None + + def count(self, cls=None): + """count the number of objects in the storage""" + all_classes = classes.values() + + if not cls: + count = 0 + for clas in all_classes: + count += len(models.storage.all(clas).values()) + else: + count += len(models.storage.all(cls).values()) + + return count diff --git a/tests/__pycache__/test_console.cpython-310.pyc b/tests/__pycache__/test_console.cpython-310.pyc new file mode 100644 index 00000000000..29ef71092ed Binary files /dev/null and b/tests/__pycache__/test_console.cpython-310.pyc differ diff --git a/tests/test_models/__pycache__/__init__.cpython-310.pyc b/tests/test_models/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 00000000000..a0a7154d22d Binary files /dev/null and b/tests/test_models/__pycache__/__init__.cpython-310.pyc differ diff --git a/tests/test_models/__pycache__/test_amenity.cpython-310.pyc b/tests/test_models/__pycache__/test_amenity.cpython-310.pyc new file mode 100644 index 00000000000..2d705b32fda Binary files /dev/null and b/tests/test_models/__pycache__/test_amenity.cpython-310.pyc differ diff --git a/tests/test_models/__pycache__/test_base_model.cpython-310.pyc b/tests/test_models/__pycache__/test_base_model.cpython-310.pyc new file mode 100644 index 00000000000..05a24abe183 Binary files /dev/null and b/tests/test_models/__pycache__/test_base_model.cpython-310.pyc differ diff --git a/tests/test_models/__pycache__/test_city.cpython-310.pyc b/tests/test_models/__pycache__/test_city.cpython-310.pyc new file mode 100644 index 00000000000..b9af3134bb5 Binary files /dev/null and b/tests/test_models/__pycache__/test_city.cpython-310.pyc differ diff --git a/tests/test_models/__pycache__/test_place.cpython-310.pyc b/tests/test_models/__pycache__/test_place.cpython-310.pyc new file mode 100644 index 00000000000..b030fba0a1f Binary files /dev/null and b/tests/test_models/__pycache__/test_place.cpython-310.pyc differ diff --git a/tests/test_models/__pycache__/test_review.cpython-310.pyc b/tests/test_models/__pycache__/test_review.cpython-310.pyc new file mode 100644 index 00000000000..82d91e13f34 Binary files /dev/null and b/tests/test_models/__pycache__/test_review.cpython-310.pyc differ diff --git a/tests/test_models/__pycache__/test_state.cpython-310.pyc b/tests/test_models/__pycache__/test_state.cpython-310.pyc new file mode 100644 index 00000000000..4fff3aabe12 Binary files /dev/null and b/tests/test_models/__pycache__/test_state.cpython-310.pyc differ diff --git a/tests/test_models/__pycache__/test_user.cpython-310.pyc b/tests/test_models/__pycache__/test_user.cpython-310.pyc new file mode 100644 index 00000000000..8cb4df348e5 Binary files /dev/null and b/tests/test_models/__pycache__/test_user.cpython-310.pyc differ diff --git a/tests/test_models/test_engine/__pycache__/__init__.cpython-310.pyc b/tests/test_models/test_engine/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 00000000000..29681317133 Binary files /dev/null and b/tests/test_models/test_engine/__pycache__/__init__.cpython-310.pyc differ diff --git a/tests/test_models/test_engine/__pycache__/test_db_storage.cpython-310.pyc b/tests/test_models/test_engine/__pycache__/test_db_storage.cpython-310.pyc new file mode 100644 index 00000000000..e111b941267 Binary files /dev/null and b/tests/test_models/test_engine/__pycache__/test_db_storage.cpython-310.pyc differ diff --git a/tests/test_models/test_engine/__pycache__/test_file_storage.cpython-310.pyc b/tests/test_models/test_engine/__pycache__/test_file_storage.cpython-310.pyc new file mode 100644 index 00000000000..16e71b438b0 Binary files /dev/null and b/tests/test_models/test_engine/__pycache__/test_file_storage.cpython-310.pyc differ