Skip to content

Instantly share code, notes, and snippets.

@chand1012
Created January 9, 2020 18:34
Show Gist options
  • Save chand1012/de170b3b6fc33e9a1056c78517dbd000 to your computer and use it in GitHub Desktop.
Save chand1012/de170b3b6fc33e9a1056c78517dbd000 to your computer and use it in GitHub Desktop.
Gets a random name from https://uinames.com/ via Python Requests
import requests
# https://uinames.com/
def random_name(amount=1, gender="", region="", minlen="", maxlen="", key="name"):
if gender != "":
gender = "?gender=" + gender
if region != "":
region = "?region=" + region
if minlen != "":
minlen = "?minlen=" + str(round(minlen))
if maxlen != "":
maxlen = "?maxlen=" + str(round(maxlen))
recv = requests.get("https://uinames.com/api/" + gender + region + minlen + maxlen)
recv.raise_for_status()
if key is "":
return recv.json()
else:
return recv.json().get(key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment