Skip to content

Instantly share code, notes, and snippets.

@AptiviCEO
Created July 29, 2022 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AptiviCEO/31218cbad397222247524b72253dc233 to your computer and use it in GitHub Desktop.
Save AptiviCEO/31218cbad397222247524b72253dc233 to your computer and use it in GitHub Desktop.
Name generator in Python using our NamesList database
# 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