Spaces:
Sleeping
Sleeping
File size: 2,745 Bytes
afe2831 05ae446 afe2831 d26938f 539c396 3ec3001 afe2831 15631cb afe2831 |
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
import requests
class RandomCharatorGeneratorTool:
name = "random_character"
description = "This tool fetches a random character from the 'https://randomuser.me/api/' open API."
inputs = ["text"] # Adding an empty list for inputs
outputs = ["json"]
def __call__(self, inputs: str):
API_URL = "https://randomuser.me/api/"
response = requests.get(API_URL)
data = response.json()['results'][0]
# Extract the relevant character information
character = {
"gender": data['gender'],
"name": {
"title": data['name']['title'],
"first": data['name']['first'],
"last": data['name']['last']
},
"location": {
"street": {
"number": data['location']['street']['number'],
"name": data['location']['street']['name']
},
"city": data['location']['city'],
"state": data['location']['state'],
"country": data['location']['country'],
"postcode": data['location']['postcode'],
"coordinates": {
"latitude": data['location']['coordinates']['latitude'],
"longitude": data['location']['coordinates']['longitude']
},
"timezone": {
"offset": data['location']['timezone']['offset'],
"description": data['location']['timezone']['description']
}
},
"email": data['email'],
"login": {
"uuid": data['login']['uuid'],
"username": data['login']['username'],
"password": data['login']['password'],
"salt": data['login']['salt'],
"md5": data['login']['md5'],
"sha1": data['login']['sha1'],
"sha256": data['login']['sha256']
},
"dob": {
"date": data['dob']['date'],
"age": data['dob']['age']
},
"registered": {
"date": data['registered']['date'],
"age": data['registered']['age']
},
"phone": data['phone'],
"cell": data['cell'],
"id": {
"name": data['id']['name'],
"value": data['id']['value']
},
"picture": {
"large": data['picture']['large'],
"medium": data['picture']['medium'],
"thumbnail": data['picture']['thumbnail']
},
"nat": data['nat']
}
return {"character": character}
|