-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomuser
executable file
·57 lines (45 loc) · 1.34 KB
/
randomuser
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import urllib.request
import json
class User(object):
data = {
"gender": "",
"name": "",
"email": "",
"username": "",
"password": ""
}
def __init__(self, **kwargs):
for key in kwargs:
self.data[key] = kwargs[key]
def getGender(self):
return self.data["gender"]
def getName(self):
return self.data["name"]
def getEmail(self):
return self.data["email"]
def getUsername(self):
return self.data["username"]
def getPassword(self):
return self.data["password"]
def ucfirst(string):
return string[0].upper() + string[1:]
def run():
response = urllib.request.urlopen("https://api.randomuser.me/")
json_string = response.read().decode("utf-8")
parsed_json = json.loads(json_string)
user = User(
gender = parsed_json["results"][0]["gender"],
name = ucfirst(parsed_json["results"][0]["name"]["first"])+" "+ucfirst(parsed_json["results"][0]["name"]["last"]),
email = parsed_json["results"][0]["email"],
username = parsed_json["results"][0]["login"]["username"],
password = parsed_json["results"][0]["login"]["password"],
)
print("Name........: "+user.getName())
print("Gender......: "+user.getGender())
print("Email.......: "+user.getEmail())
print("Username....: "+user.getUsername())
print("Password....: "+user.getPassword())
if __name__ == "__main__":
run()