Created
July 29, 2022 12:23
-
-
Save AptiviCEO/31218cbad397222247524b72253dc233 to your computer and use it in GitHub Desktop.
Name generator in Python using our NamesList database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Necessary imports for this app | |
from urllib.request import urlopen | |
import argparse | |
import random | |
# Functions | |
def genname(num): | |
# Get first names | |
firstNames = urlopen('https://cdn.jsdelivr.net/gh/EoflaOE/NamesList@master/Processed/FirstNames.txt').read() | |
firstNamesArray = firstNames.decode('utf-8').splitlines() | |
# Get last names | |
lastNames = urlopen('https://cdn.jsdelivr.net/gh/EoflaOE/NamesList@master/Processed/Surnames.txt').read() | |
lastNamesArray = lastNames.decode('utf-8').splitlines() | |
# Generate n names | |
for x in range(num): | |
firstName = firstNamesArray[random.randint(0,len(firstNamesArray))] | |
lastName = lastNamesArray[random.randint(0,len(lastNamesArray))] | |
print(firstName + " " + lastName) | |
# Arguments parsing | |
parser = argparse.ArgumentParser() | |
parser.add_argument('numberofnames', type=int, help="How many names to generate?") | |
args = parser.parse_args() | |
genname(args.numberofnames) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment