this project is consist of 2 main parts; first we have the models.py
file, where the collection's schema is.
then, we have the main.py
which has the responsibility to do the CRUD operations on the database.
Notice: I have commented codes related to logger because It was more of a distraction due to the fact that it logs the the information in the terminal where the output of the command also exists! but you can uncomment it based on your desire :)
APOLOGY! I wanted to use MongoDB-Atlas
to deploy the database... I did it but I couldn't insert any data :( now you need to run a MongoDB instanse on your localhost
port 27017
(which is the default port of it). alternative way, you can modify the connection_string
to connect to your own MongoDB database (it will create the database and collection automatically)
first you need to create a virtual environment, cd to the directory where this file is and then run the following command:
Create and Activate a Virtual Environment:
- Linux/mac:
$ pip install virtualenv
$ virtualenv [YourVenvName]
$ source [YourVenvName]/bin/activate
- Windows:
pip install virtualenv
python -m venv [YourVenvName]
[YourVenvName]/Scripts/activate
install the required libraries and run the code:
$ pip install -r requirements.txt
execute READ operation:
$ python main.py list
or if you want to search for a specific contact:
$ python main.py search -f <first name> -l <last name>
execute CREATE operation:
$ python main.py create -f <first name> -l <last name> -d <country code> -n <phone number> [-C <country>] [-c <city>] [-a <address>]
execute UPDATE operation:
$ python main.py create -f <first name> -l <last name> [-d <new country code>] [-n <new phone number>] [-C <new country>] [-c <new city>] [-a <new address>] [-F <new first name>] [-L <new last name>]
execute DELETE operation:
$ python main.py delete -f <first name> -l <last name>
I'm more than happy to hear your feedbacks and collaborate with you guys!
if you had any problem contributing on the project, feel free to contact me:
- Amirhoseein Khalili