This script generates a specified number of random contacts in various formats, including VCF, XML, CFG, JSON, and CSV. Each contact contains a first name, last name, email address, birthday, and a random number of phone numbers with corresponding labels. The script uses the Faker library to generate realistic contact data.
The script relies on the following Python packages:
-
vobject
: A Python package for parsing and creating iCalendar and vCard files. You can learn more about it here: https://github.com/eventable/vobject -
faker
: A Python package for generating realistic fake data. It is used to generate random names and email addresses for the contacts. You can find more information here: https://github.com/joke2k/faker
-
Make sure you have Python 3.x installed on your system. If not, you can download and install Python from the official website: Python Downloads.
-
Clone this repository or download the script
generate_contacts.py
to your local machine. -
Install the required Python dependencies by running the following command in your terminal:
pip install vobject faker
If you have both Python 2 and Python 3 installed, and pip is associated with Python 2, use pip3 instead:
pip3 install vobject faker
Note: If pip or pip3 command is not recognized, make sure to install pip for your Python version.
-
Changing the number of contacts generated: By default, the script generates 5000 contacts. However, users can modify the
range
value in the linecontacts = [generate_contact() for _ in range(5000)]
. Change5000
to your desired number. -
Changing the range of ages for generated contacts: By default, the script generates contacts with ages between 18 and 80. However, the user may want to generate contacts with different age ranges. To do this, they can modify the values of the MIN_AGE and MAX_AGE constants at the beginning of the script.
-
Changing the labels for phone numbers: the user may want to customize these labels used for phone numbers by updating the
labels
list in the script to better suit their needs -
Adding or removing contact information fields: The script currently generates first name, last name, email, birthday, phone numbers, and phone number labels. If users want to include additional fields, such as company or address, they can modify the generate_contact() function accordingly. Similarly, if users want to exclude certain fields, they can simply remove the corresponding lines of code.
-
Changing the file formats generated: The script currently generates VCF, XML, CFG, JSON, and CSV files. If users only need certain file formats, they can remove the corresponding function calls at the bottom of the script.
-
Modifying the file naming convention or output directory: By default, the script saves the generated files to an "output" directory within the same directory as the script itself. Users can modify the output directory path and/or the file naming convention by changing the relevant variables at the top of the script.
-
Open the generate_contacts.py file in a text editor.
-
Customize the script if needed. For example, you can modify the number of contacts to generate by changing the value in the range() function. Save the script.
-
Open your terminal or command prompt and navigate to the directory where the script is located.
-
Run the script using the following command:
python generate_contacts.py
You can also run the script in any python IDE like VSCode.
-
The script will generate random contacts in various file formats, including VCF, XML, CFG, JSON, and CSV. By default, the script saves the generated files to an "output" directory within the same directory as the script itself
-
You can import the generated files into your contact manager, phone app or simulator to add the contacts
Note: Feel free to modify the code and adapt it to your requirements. Enjoy generating contacts!
I have provided a sample output folder output
in the repository for users to check the expected format and structure of the output files generated by the script.
For any questions or issues, please feel free to reach out to me