Created
January 9, 2020 18:34
-
-
Save chand1012/de170b3b6fc33e9a1056c78517dbd000 to your computer and use it in GitHub Desktop.
Gets a random name from https://uinames.com/ via Python Requests
This file contains hidden or 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
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