Skip to content

QuasarX35/randUserGen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

This Python code generates random Malaysian names and attributes, creates random NRIC numbers based on the date of birth and gender, and writes the generated data to a file. It also reads configuration options from a text file.

Steps to Use

Here are the steps to use the script:

  1. Install the required Python libraries - requests, BeautifulSoup, faker pip install requests beautifulsoup4 Faker

  2. Download the script and create a configuration file named "config.txt" in the same directory as the script.

  3. Define the configuration options in the "config.txt" file. The options include the number of users to generate, the format for the user IDs, whether to replace spaces in names with a specified character, and the character to replace spaces with. The configuration file has a specific format described in the function parse_config().

  4. Call the script by running it from the command line: python script.py

  5. The script will generate fake personal details including name, gender, and NRIC number for the specified number of users. The script will output the results to the console.

Libraries Used

The following Python libraries are used in this code:

  • requests
  • BeautifulSoup
  • Faker

Functions

generate_fake_nric This function generates a random fake Malaysian NRIC number based on the date of birth and gender.

Parameters

  • dob: date of birth string
  • dob_format: format of date of birth string (default: '%Y-%m-%d')
  • gender: gender of the person (default: 'M')

Return value

  • string representation of the generated NRIC number

parse_config This function reads a configuration file and returns a dictionary of configuration options.

Parameters

  • file_path: The path to the configuration file.

Return value

  • A dictionary containing the configuration options.

Main code

The main code generates random Malaysian names and attributes using a website that generates random names. It then generates random NRIC numbers using the generate_fake_nric function and writes the generated data to a file. It reads configuration options from a text file using the parse_config function.

Configuration file

The configuration file should contain configuration options in the following format:

key: value

If a line starts with "#" or is empty, it will be ignored.

If a line starts with "default_", it will be treated as a default value. Default values are stored in a separate dictionary and are used when a key is not found in the main dictionary.

Configuration options

  • num_users: the number of users to generate
  • replace_spaces: whether to replace spaces in names with a specific character (default: False)
  • space_char: the character to use when replacing spaces in names (default: '-')
  • id_format: the format to use for the user IDs (default: 'USER{:03d}')

Note

This code was tested with Python version 3.9.7. The script uses web scraping techniques to generate fake personal details, so it may be affected by changes to the website structure. The script should not be used for any illegal or unethical purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages