rodrigosantosbr

[Py] Gender prediction with Namsor API

Apr 6th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. import json
  2. import requests
  3.  
  4. myKey = "aeiou"
  5. fullname = "Maria do Socorro Alves"
  6. countryIso2 = "BR"
  7. url = "https://v2.namsor.com/NamSorAPIv2/api2/json/genderFullGeo/{}/BR".format(fullname)
  8.  
  9. headers = {
  10.     'accept': 'application/json',
  11.     'X-API-KEY': myKey,
  12. }
  13.  
  14. try:
  15.     response = requests.get(url, headers=headers)
  16.     if response.status_code == 200:
  17.         response.encoding = 'utf-8'
  18.         json_response = response.json()
  19.         print(json_response['likelyGender']) #female
  20. except HTTPError as http_err:
  21.     pass
Add Comment
Please, Sign In to add comment