├── product_inmemory_db.py ├── README.md ├── LICENSE ├── main.py ├── .gitignore └── product.py /product_inmemory_db.py: -------------------------------------------------------------------------------- 1 | class ProductInMemoryDb: 2 | products_list = [] 3 | 4 | def __init__(self,data:dict): 5 | self.products_list.append(data) 6 | 7 | def __str__(self) -> str: 8 | return f"Product list : \n {self.products_list}" 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Documentation 2 | 3 | [It is a simple CRUD application made with pure Python base on OOP concepts. There are some really simple terms to follow. If you're curious to run the program and see how it works, 1- clone this repo into your local system 2- make an object in main.py and then you can easily start your adventure](https://linktodocumentation) 4 | 5 | 6 | ## Badges 7 | 8 | 9 | [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/) 10 | 11 | 12 | 13 | ## Authors 14 | 15 | - (https://github.com/alireza-hashemii) 16 | 17 | 18 | ## 🛠 Skills 19 | Python , OOP , Git 20 | 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | 4 | Copyright (c) 2022 alireza-hashemii 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from product import Product 2 | from datetime import datetime 3 | 4 | 5 | # Making an object of product class 6 | def main(): 7 | 8 | product1 = Product(1,4,"iPhone 13","Nothing","""The iPhone 13 and iPhone 13 Mini (stylized as iPhone 13 mini) are smartphones designed, developed, marketed, and sold by Apple Inc. They are the fifteenth 9 | generation of iPhones (succeeding the iPhone 12 and iPhone 12 Mini respectively). They were unveiled at an Apple Event in Apple Park in 10 | iPhone 13 Pro and iPhone 13 Pro Max flagships. Pre-orders for the iPhone 13 and iPhone 13 Mini began on September 17, 2021. They were officially released on September 24, 2021. """, 11 | "product","https://en.wikipedia.org/wiki/IPhone_13",True,"nothing",1.0,1.1300,999.0,1,1,True,datetime.now(),datetime.now()) 12 | 13 | product2 = Product(2,4,"iPhone 15","hilarious one","""Ti phone 15 and the mini one (stylized as iPhone 13 mini) are smartphones designed, developed, marketed, and sold by Apple Inc. They are the fifteenth 14 | generation of iPhones They were unveiled at an Apple Event in Apple Park in Cupertino, California on September 14, 2021, alongside the higher-priced 15 | iPhone 13 Pro and iPhone 13 Pro Max flagships. Pre-orders for the iPhone 13 and iPhone 13 Mini began on September 17, 2021. They were officially released on September 24, 2021. """, 16 | "product","https://en.storemall.org/Longiji/Iphone15",True,"occuiped",1.0,1.1900,1500.0,2,1,False,datetime.now(),datetime.now()) 17 | 18 | # Create 19 | print(product1.create()) 20 | product2.create() 21 | 22 | 23 | # Update 24 | print(product1.update(1,"it has been updated.")) 25 | 26 | # Read 27 | print(product1.read(2)) 28 | 29 | # ReadAll 30 | print(product1.read_all()) 31 | 32 | # Delete 33 | print(product1.delete(2)) 34 | 35 | 36 | print("-----------------------------") 37 | # Return True if product1 is an instance of class Product 38 | print(isinstance(product1,Product)) 39 | # Return type of object product1 40 | print(type(product1)) 41 | 42 | 43 | 44 | # This module wont work if it's imported 45 | if __name__ == "__main__": 46 | main() -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | ### Git ### 3 | # Created by git for backups. To disable backups in Git: 4 | # $ git config --global mergetool.keepBackup false 5 | *.orig 6 | 7 | # Created by git when using merge tools for conflicts 8 | *.BACKUP.* 9 | *.BASE.* 10 | *.LOCAL.* 11 | *.REMOTE.* 12 | *_BACKUP_*.txt 13 | *_BASE_*.txt 14 | *_LOCAL_*.txt 15 | *_REMOTE_*.txt 16 | *LICENSE 17 | ### Python ### 18 | # Byte-compiled / optimized / DLL files 19 | __pycache__/ 20 | *.py[cod] 21 | *$py.class 22 | 23 | # C extensions 24 | *.so 25 | 26 | # Distribution / packaging 27 | .Python 28 | build/ 29 | develop-eggs/ 30 | dist/ 31 | downloads/ 32 | eggs/ 33 | .eggs/ 34 | lib/ 35 | lib64/ 36 | parts/ 37 | sdist/ 38 | var/ 39 | wheels/ 40 | share/python-wheels/ 41 | *.egg-info/ 42 | .installed.cfg 43 | *.egg 44 | MANIFEST 45 | 46 | # PyInstaller 47 | # Usually these files are written by a python script from a template 48 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 49 | *.manifest 50 | *.spec 51 | 52 | # Installer logs 53 | pip-log.txt 54 | pip-delete-this-directory.txt 55 | 56 | # Unit test / coverage reports 57 | htmlcov/ 58 | .tox/ 59 | .nox/ 60 | .coverage 61 | .coverage.* 62 | .cache 63 | nosetests.xml 64 | coverage.xml 65 | *.cover 66 | *.py,cover 67 | .hypothesis/ 68 | .pytest_cache/ 69 | cover/ 70 | 71 | # Translations 72 | *.mo 73 | *.pot 74 | 75 | # Django stuff: 76 | *.log 77 | local_settings.py 78 | db.sqlite3 79 | db.sqlite3-journal 80 | 81 | # Flask stuff: 82 | instance/ 83 | .webassets-cache 84 | 85 | # Scrapy stuff: 86 | .scrapy 87 | 88 | # Sphinx documentation 89 | docs/_build/ 90 | 91 | # PyBuilder 92 | .pybuilder/ 93 | target/ 94 | 95 | # Jupyter Notebook 96 | .ipynb_checkpoints 97 | 98 | # IPython 99 | profile_default/ 100 | ipython_config.py 101 | 102 | 103 | # commonly ignored for libraries. 104 | .pdm.toml 105 | 106 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 107 | __pypackages__/ 108 | 109 | # Celery stuff 110 | celerybeat-schedule 111 | celerybeat.pid 112 | 113 | # SageMath parsed files 114 | *.sage.py 115 | 116 | # Environments 117 | .env 118 | .venv 119 | env/ 120 | venv/ 121 | ENV/ 122 | env.bak/ 123 | venv.bak/ 124 | 125 | # Spyder project settings 126 | .spyderproject 127 | .spyproject 128 | 129 | # Rope project settings 130 | .ropeproject 131 | 132 | # mkdocs documentation 133 | /site 134 | 135 | # mypy 136 | .mypy_cache/ 137 | .dmypy.json 138 | dmypy.json 139 | 140 | # Pyre type checker 141 | .pyre/ 142 | 143 | # pytype static type analyzer 144 | .pytype/ 145 | 146 | # Cython debug symbols 147 | cython_debug/ 148 | 149 | # PyCharm 150 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 151 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 152 | # and can be added to the global gitignore or merged into this file. For a more nuclear 153 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 154 | #.idea/ 155 | 156 | ### Python Patch ### 157 | # Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration 158 | poetry.toml 159 | 160 | 161 | ### VisualStudioCode ### 162 | .vscode/* 163 | !.vscode/settings.json 164 | !.vscode/tasks.json 165 | !.vscode/launch.json 166 | !.vscode/extensions.json 167 | !.vscode/*.code-snippets 168 | 169 | # Local History for Visual Studio Code 170 | .history/ 171 | 172 | # Built Visual Studio Code Extensions 173 | *.vsix 174 | 175 | ### VisualStudioCode Patch ### 176 | # Ignore all local history of files 177 | .history 178 | .ionide 179 | 180 | ### Windows ### 181 | # Windows thumbnail cache files 182 | Thumbs.db 183 | Thumbs.db:encryptable 184 | ehthumbs.db 185 | ehthumbs_vista.db 186 | 187 | # Dump file 188 | *.stackdump 189 | 190 | # Folder config file 191 | [Dd]esktop.ini 192 | 193 | # Recycle Bin used on file shares 194 | $RECYCLE.BIN/ 195 | 196 | # Windows Installer files 197 | *.cab 198 | *.msi 199 | *.msix 200 | *.msm 201 | *.msp 202 | 203 | # Windows shortcuts 204 | *.lnk 205 | 206 | -------------------------------------------------------------------------------- /product.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | from product_inmemory_db import ProductInMemoryDb 3 | 4 | 5 | class Product(): 6 | 7 | def __init__(self,product_id:int,category_id:int,title:str,short_description:str,description:str, 8 | slug:str,permalink:str,Is_Available:bool,sku:str,price:float,regular_price:float, 9 | sale_price:float,manage_stock:int,stock_quantity:int,Is_Visible:bool, 10 | date_created_gmt:datetime,date_modified_gmt:datetime): 11 | 12 | assert product_id >= 0,f"Product id should be greater than zero but {product_id} is not" 13 | assert category_id >= 0,f"category id should be greater than zero but {product_id} is not" 14 | 15 | self.product_id = product_id 16 | self.category_id = category_id 17 | self.title = title 18 | self.short_description = short_description 19 | self.description = description 20 | self.slug = slug 21 | self.permalink = permalink 22 | self.is_available = Is_Available 23 | self.sku = sku 24 | self.price = price 25 | self.regular_price = regular_price 26 | self.sale_price = sale_price 27 | self.manage_stock = manage_stock 28 | self.stock_quantity = stock_quantity 29 | self.is_visible = Is_Visible 30 | self.date_created_gmt = date_created_gmt 31 | self.date_modified_gmt = date_modified_gmt 32 | 33 | def create(self): 34 | dict = {} 35 | for key,value in self.__dict__.items(): 36 | dict[key] = value 37 | object = ProductInMemoryDb(dict) 38 | return object 39 | 40 | 41 | def read(self,id:int): 42 | for product in ProductInMemoryDb.products_list: 43 | if product["product_id"] == id: 44 | return product 45 | return("No products found with the given id.") 46 | 47 | @classmethod 48 | def read_all(cls): 49 | for product in ProductInMemoryDb.products_list: 50 | print(product,end="\r") 51 | 52 | 53 | def update(self,id:int,title:str): 54 | for product in ProductInMemoryDb.products_list: 55 | if product["product_id"] == id: 56 | product["title"] = title 57 | return(self.__repr__()) 58 | return("No products found with the given id.") 59 | 60 | 61 | 62 | def delete(self,id:int): 63 | for product in ProductInMemoryDb.products_list: 64 | if product["product_id"] == id: 65 | ProductInMemoryDb.products_list.remove(product) 66 | print("succesfully deleted.") 67 | return(ProductInMemoryDb.products_list) 68 | return("No products found with the given id.") 69 | 70 | 71 | def __repr__(self) -> str: 72 | return(f"Product is : {self.product_id} \n {self.title} \n {self.category_id} \n {self.short_description} \n {self.description} \n {self.slug} \n {self.permalink} \n {self.is_available} \n {self.sku} \n {self.price} \n {self.stock_quantity} \n {self.date_created_gmt} \n {self.date_modified_gmt}") 73 | 74 | 75 | product1 = Product(1,4,"iPhone 13","Nothing","""The iPhone 13 and iPhone 13 Mini (stylized as iPhone 13 mini) are smartphones designed, developed, marketed, and sold by Apple Inc. They are the fifteenth 76 | generation of iPhones (succeeding the iPhone 12 and iPhone 12 Mini respectively). They were unveiled at an Apple Event in Apple Park in 77 | iPhone 13 Pro and iPhone 13 Pro Max flagships. Pre-orders for the iPhone 13 and iPhone 13 Mini began on September 17, 2021. They were officially released on September 24, 2021. """, 78 | "product","https://en.wikipedia.org/wiki/IPhone_13",True,"nothing",1.0,1.1300,999.0,1,1,True,datetime.now(),datetime.now()) 79 | 80 | product2 = Product(2,4,"iPhone 14","Nothing","""The iPhone 13 and iPhone 13 Mini (stylized as iPhone 13 mini) are smartphones designed, developed, marketed, and sold by Apple Inc. They are the fifteenth 81 | generation of iPhones (succeeding the iPhone 12 and iPhone 12 Mini respectively). They were unveiled at an Apple Event in Apple Park in 82 | iPhone 13 Pro and iPhone 13 Pro Max flagships. Pre-orders for the iPhone 13 and iPhone 13 Mini began on September 17, 2021. They were officially released on September 24, 2021. """, 83 | "product","https://en.wikipedia.org/wiki/IPhone_13",True,"nothing",1.0,1.1300,999.0,1,1,True,datetime.now(),datetime.now()) 84 | 85 | #! 1 - make instances in main.py suitable. \ 2 - polish up the code \ 3 - make str and repr method prettier --------------------------------------------------------------------------------